From 501b4f27c5f8e114cc56762e30105112e86b885c Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 25 Jul 2026 13:47:01 +0200 Subject: kapi: fix driver probing Previously, a driver was only bound after probing was successful. However, if the probing itself relies (directly or indirectly) on the device having a bound driver, probing fails. This patchset introduces a new device state to mark that we are currently probing and thus the bound driver is not yet definitively bound to the device. This allows us to bind early, without violating the perceived device state. --- kernel/kapi/devices/driver_registry.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'kernel') diff --git a/kernel/kapi/devices/driver_registry.cpp b/kernel/kapi/devices/driver_registry.cpp index 5784694a..2ba9a485 100644 --- a/kernel/kapi/devices/driver_registry.cpp +++ b/kernel/kapi/devices/driver_registry.cpp @@ -105,15 +105,19 @@ namespace kapi::devices for (auto const & candidate : candidates) { + device->bind_driver(candidate.driver_handle); + device->set_state(state::probing); + auto probed = candidate.driver_handle->probe(*device); if (probed) { - device->bind_driver(candidate.driver_handle); device->set_state(state::bound); kstd::println("[OS:DRV] Bound device {} (priority {})", device->name(), candidate.priority); return; } + device->bind_driver(kstd::weak_ptr{}); + kstd::println(kstd::print_sink::stderr, "[OS:DRV] probe() failed for device {} (priority {}): {}", device->name(), candidate.priority, probed.error().message()); } -- cgit v1.2.3