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 <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Jérôme Duval 2024-10-22 17:49:21 +02:00
parent 1b05bf1a7e
commit 53cab618ef

View File

@ -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);