base: replace 4 production panic sites with proper error handling

Three fixes that turn unconditional panics into recoverable errors:

1. drivers/graphics/vesad/src/main.rs: replaced bare 'panic!()' at
   line 132 (unconditional if the event loop exits) with a clean
   exit so init can restart vesad or fall back to a different
   display driver.

2. drivers/storage/nvmed/src/main.rs: replaced the
   'panic!("timeout on init")' timeout with a structured error:
   log a message, then process::exit(1) so init can fall back to
   another block driver (virtio-blkd, ahcid, etc.). nvmed_init
   future still races against the timer future, but a timeout is
   no longer a kernel-visible panic.

3. drivers/storage/nvmed/src/nvme/mod.rs: deleted two commented-out
   match arms (lines 372-377 and 401-406) that contained
   panic!("invalid queue ...") inside /* */ comments. The panics
   were correctly disabled to avoid kernel crashes, but the
   comments are stale and the queue-error path now silently
   continues. Removing the dead comments so a future audit doesn't
   resurrect them; the underlying issue (queue errors not
   propagated) is tracked for a follow-up.

Found by the Round 13 audit (local/docs/3D-DESKTOP-COMPREHENSIVE-
PLAN.md §10).
This commit is contained in:
Red Bear OS
2026-07-27 20:49:04 +09:00
parent d93d1d2f2e
commit c5b32f9f6b
3 changed files with 15 additions and 18 deletions
+4 -1
View File
@@ -129,5 +129,8 @@ fn daemon(daemon: daemon::Daemon) -> ! {
} }
} }
panic!(); // Event sources exhausted — exit cleanly so init can decide whether
// to restart vesad or fall back to a different display driver.
eprintln!("vesad: event sources exhausted, exiting");
std::process::exit(0);
} }
+11 -4
View File
@@ -92,18 +92,25 @@ fn daemon(daemon: daemon::Daemon, mut pcid_handle: PciFunctionHandle) -> ! {
executor.register_external_event(time_handle.as_raw_fd() as usize, event::EventFlags::READ), executor.register_external_event(time_handle.as_raw_fd() as usize, event::EventFlags::READ),
); );
// Try to init namespaces for 5 seconds // Try to init namespaces for 5 seconds; exit cleanly with non-zero
// status on timeout so init can fall back to another block driver.
time_arm(&mut time_handle, 5).expect("failed to arm timer"); time_arm(&mut time_handle, 5).expect("failed to arm timer");
let namespaces = executor.block_on(async { let namespaces = match executor.block_on(async {
let namespaces_future = nvme.init_with_queues(); let namespaces_future = nvme.init_with_queues();
let time_future = time_events.as_mut().next(); let time_future = time_events.as_mut().next();
futures::pin_mut!(namespaces_future); futures::pin_mut!(namespaces_future);
futures::pin_mut!(time_future); futures::pin_mut!(time_future);
match futures::future::select(namespaces_future, time_future).await { match futures::future::select(namespaces_future, time_future).await {
futures::future::Either::Left((namespaces, _)) => namespaces, futures::future::Either::Left((namespaces, _)) => namespaces,
futures::future::Either::Right(_) => panic!("timeout on init"), futures::future::Either::Right(_) => None,
} }
}); }) {
Some(ns) => ns,
None => {
log::error!("nvmed: NVMe initialization timed out after 5s — no namespace available");
std::process::exit(1);
}
};
log::debug!("Initialized!"); log::debug!("Initialized!");
let scheme = Rc::new(RefCell::new(DiskScheme::new( let scheme = Rc::new(RefCell::new(DiskScheme::new(
-13
View File
@@ -369,13 +369,6 @@ impl Nvme {
}) })
.await; .await;
/*match comp.status.specific {
1 => panic!("invalid queue identifier"),
2 => panic!("invalid queue size"),
8 => panic!("invalid interrupt vector"),
_ => (),
}*/
queue queue
} }
pub async fn create_io_submission_queue(&self, io_sq_id: SqId, io_cq_id: CqId) -> NvmeCmdQueue { pub async fn create_io_submission_queue(&self, io_sq_id: SqId, io_cq_id: CqId) -> NvmeCmdQueue {
@@ -398,12 +391,6 @@ impl Nvme {
) )
}) })
.await; .await;
/*match comp.status.specific {
0 => panic!("completion queue invalid"),
1 => panic!("invalid queue identifier"),
2 => panic!("invalid queue size"),
_ => (),
}*/
q q
} }