From 9079144ace00c939e2fb92a3bfd1c119e1b66b74 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 8 Jun 2008 19:57:44 +0000 Subject: [PATCH] * The bus value of child devices are not necessarily the same as the one of the parent bus. It is possible that there are other busses below the root bus and we must therefore always iterate through the child devices when searching for a device with a bus unequal to our own. Otherwise devices for non-null busses could not be found which would lead to crashes in operations involving them. * Adding a panic in case finding a device failed as this should clearly not happen. This probably fixes bug #2293 and might affect #2284 too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25867 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/bus_managers/pci/pci.cpp | 5 +++-- src/add-ons/kernel/bus_managers/pci/pci_device.cpp | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/pci/pci.cpp b/src/add-ons/kernel/bus_managers/pci/pci.cpp index 79df9cd80b..d6b7d64db9 100644 --- a/src/add-ons/kernel/bus_managers/pci/pci.cpp +++ b/src/add-ons/kernel/bus_managers/pci/pci.cpp @@ -1301,12 +1301,13 @@ PCIDev * PCI::_FindDevice(PCIBus *current, int domain, uint8 bus, uint8 device, uint8 function) { - if (current->domain == domain && current->bus == bus) { + if (current->domain == domain) { // search device on this bus for (PCIDev *child = current->child; child != NULL; child = child->next) { - if (child->device == device && child->function == function) + if (child->bus == bus && child->device == device + && child->function == function) return child; if (child->child != NULL) { diff --git a/src/add-ons/kernel/bus_managers/pci/pci_device.cpp b/src/add-ons/kernel/bus_managers/pci/pci_device.cpp index fe795fdaad..78c0099b74 100644 --- a/src/add-ons/kernel/bus_managers/pci/pci_device.cpp +++ b/src/add-ons/kernel/bus_managers/pci/pci_device.cpp @@ -124,6 +124,9 @@ pci_device_init_driver(device_node* node, void** _cookie) return B_NO_MEMORY; device->device = gPCI->FindDevice(domain, bus, deviceNumber, function); + if (device->device == NULL) + panic("device not found!\n"); + device->node = node; *_cookie = device;