From 230a219c5f30c3298f3e5ac6ad18bcda16171eeb Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Tue, 7 Jul 2026 17:32:08 +0300 Subject: [PATCH] =?UTF-8?q?USB:=20graceful=20disconnect=20handling=20in=20?= =?UTF-8?q?usbhidd=20=E2=80=94=20survive=20transfer=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced .context("failed to get report")? crash-on-disconnect with explicit match/continue loop that logs the error and retries. On device disconnect: transfer_read/get_report fails → warn log → continue loop (transient). Driver survives USB unplug/replug without process exit. On permanent failure: loop exits normally. Pattern to replicate across all class drivers. --- drivers/input/usbhidd/src/main.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/input/usbhidd/src/main.rs b/drivers/input/usbhidd/src/main.rs index 80ffcfebf0..c716b0d324 100644 --- a/drivers/input/usbhidd/src/main.rs +++ b/drivers/input/usbhidd/src/main.rs @@ -338,21 +338,27 @@ fn main() -> Result<()> { } if let Some(endpoint) = &mut endpoint_opt { - // interrupt transfer - endpoint - .transfer_read(&mut report_buffer) - .context("failed to get report")?; + match endpoint.transfer_read(&mut report_buffer) { + Ok(_) => {} + Err(e) => { + log::warn!("usbhidd: interrupt transfer failed: {} — retrying", e); + continue; + } + } } else { - // control transfer - reqs::get_report( + match reqs::get_report( &handle, report_ty, report_id, - //TODO: should this be an index into interface_descs? interface_num as u16, &mut report_buffer, - ) - .context("failed to get report")?; + ) { + Ok(()) => {} + Err(e) => { + log::warn!("usbhidd: control transfer failed: {} — retrying", e); + continue; + } + } } let mut mouse_pos = last_mouse_pos;