From 53cab618ef8d3eaad653aad96f5004ecfdce1b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 22 Oct 2024 17:49:21 +0200 Subject: [PATCH] kernel/legacy_drivers: check priority when finding a driver with the same leaf name * fix get_priority(): only compares the path length, not the buffer length. * fix #17264 second part (don't replace the user driver with the system one) Change-Id: I199ba5751884a4f2ec86f6d9fb81cd560fe164a8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8500 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- src/system/kernel/device_manager/legacy_drivers.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/device_manager/legacy_drivers.cpp b/src/system/kernel/device_manager/legacy_drivers.cpp index 57feb12571..3d32b17600 100644 --- a/src/system/kernel/device_manager/legacy_drivers.cpp +++ b/src/system/kernel/device_manager/legacy_drivers.cpp @@ -529,12 +529,11 @@ get_priority(const char* path) }; KPath pathBuffer; - for (uint32 index = 0; index < sizeof(whichPath) / sizeof(whichPath[0]); - index++) { + for (uint32 index = 0; index < B_COUNT_OF(whichPath); index++) { if (__find_directory(whichPath[index], gBootDevice, false, pathBuffer.LockBuffer(), pathBuffer.BufferSize()) == B_OK) { pathBuffer.UnlockBuffer(); - if (!strncmp(pathBuffer.Path(), path, pathBuffer.BufferSize())) + if (strncmp(pathBuffer.Path(), path, pathBuffer.Length()) == 0) return index; } else pathBuffer.UnlockBuffer(); @@ -593,7 +592,7 @@ add_driver(const char* path, image_id image) legacy_driver* driver = sDriverHash->Lookup(get_leaf(path)); if (driver != NULL) { // we know this driver - if (strcmp(driver->path, path) != 0) { + if (strcmp(driver->path, path) != 0 && priority >= driver->priority) { // TODO: do properly, but for now we just update the path if it // isn't the same anymore so rescanning of drivers will work in // case this driver was loaded so early that it has a boot module @@ -604,7 +603,7 @@ add_driver(const char* path, image_id image) driver->binary_updated = true; } - // TODO: check if this driver is a different one and has precendence + // TODO: check if this driver is a different one and has precedence // (ie. common supersedes system). //dprintf("new driver has priority %ld, old %ld\n", priority, driver->priority); if (priority >= driver->priority) { @@ -749,14 +748,14 @@ handle_driver_events(void* /*_fs*/, int /*iteration*/) } case kAddWatcher: - TRACE((" add watcher %ld:%lld\n", event->node.device, + TRACE((" add watcher %" B_PRId32 ":%" B_PRIdINO "\n", event->node.device, event->node.node)); add_node_listener(event->node.device, event->node.node, B_WATCH_STAT | B_WATCH_NAME, sDriverWatcher); break; case kRemoveWatcher: - TRACE((" remove watcher %ld:%lld\n", event->node.device, + TRACE((" remove watcher %" B_PRId32 ":%" B_PRIdINO "\n", event->node.device, event->node.node)); remove_node_listener(event->node.device, event->node.node, sDriverWatcher);