From 11ef8173667bac7f0a0d8dad921a413edd376c3f Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Wed, 8 Jul 2026 00:31:03 +0300 Subject: [PATCH] =?UTF-8?q?USB:=20P0=20fix=20=E2=80=94=20eliminate=20runti?= =?UTF-8?q?me=20panics=20in=20usbscsid=20main=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IMPROVEMENT-PLAN.md §10.1.6: critical safety fix. usbscsid main.rs had 3 runtime unwrap sites that would panic the daemon on transient errors: 1. Line 106: debug block 0 read on init — now uses if-let to skip the debug print if the read fails (disconnected device, media error). The device still registers its scheme. 2. Line 144: event_queue event unwrap — now handles Err() with eprintln + continue instead of panic. 3. Line 147: scheme.tick() unwrap — now handles Err() with eprintln instead of panic. Scheme tick failures propagate gracefully — the event loop continues, the daemon survives. This matches the Linux 7.1 pattern of logging USB errors without crashing the daemon. --- drivers/storage/usbscsid/src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/storage/usbscsid/src/main.rs b/drivers/storage/usbscsid/src/main.rs index 166921535d..097f61f39b 100644 --- a/drivers/storage/usbscsid/src/main.rs +++ b/drivers/storage/usbscsid/src/main.rs @@ -103,8 +103,9 @@ fn daemon(daemon: daemon::Daemon) -> ! { } let mut buffer = [0u8; 512]; - scsi.read(&mut *protocol, 0, &mut buffer).unwrap(); - println!("DISK CONTENT: {}", base64::encode(&buffer[..])); + if let Ok(()) = scsi.read(&mut *protocol, 0, &mut buffer).map(|_| ()) { + println!("DISK CONTENT: {}", base64::encode(&buffer[..])); + } let event_queue = event::EventQueue::new().unwrap(); @@ -141,10 +142,19 @@ fn daemon(daemon: daemon::Daemon) -> ! { .unwrap(); for event in event_queue { - match event.unwrap().user_data { - Event::Scheme => driver_block::FuturesExecutor - .block_on(scheme.tick()) - .unwrap(), + let event = match event { + Ok(e) => e, + Err(e) => { + eprintln!("usbscsid: event error: {}", e); + continue; + } + }; + match event.user_data { + Event::Scheme => { + if let Err(e) = driver_block::FuturesExecutor.block_on(scheme.tick()) { + eprintln!("usbscsid: scheme tick error: {}", e); + } + } } }