From 5d14311137a0216cb09d0965a3c5165e6dd17702 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 6 May 2009 02:03:25 +0000 Subject: [PATCH] When doing removal notifications for USB devices, report the hub after the children. Otherwise a driver that builds up a device hierarchy could run into trouble when the parent hub is removed before its child devices. Not that there were any drivers that do so, but it just seems more correct. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30641 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/bus_managers/usb/Hub.cpp | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/usb/Hub.cpp b/src/add-ons/kernel/bus_managers/usb/Hub.cpp index ef2ba27aad..d8cc9c2887 100644 --- a/src/add-ons/kernel/bus_managers/usb/Hub.cpp +++ b/src/add-ons/kernel/bus_managers/usb/Hub.cpp @@ -349,16 +349,16 @@ Hub::ReportDevice(usb_support_descriptor *supportDescriptors, uint32 supportDescriptorCount, const usb_notify_hooks *hooks, usb_driver_cookie **cookies, bool added, bool recursive) { - TRACE("reporting hub\n"); + status_t result = B_UNSUPPORTED; - // Report ourselfs first - status_t result = Device::ReportDevice(supportDescriptors, - supportDescriptorCount, hooks, cookies, added, recursive); + if (added) { + // Report hub before children when adding devices + TRACE("reporting hub before children\n"); + result = Device::ReportDevice(supportDescriptors, + supportDescriptorCount, hooks, cookies, added, recursive); + } - if (!recursive) - return result; - - for (int32 i = 0; i < fHubDescriptor.num_ports; i++) { + for (int32 i = 0; recursive && i < fHubDescriptor.num_ports; i++) { if (!fChildren[i]) continue; @@ -367,6 +367,14 @@ Hub::ReportDevice(usb_support_descriptor *supportDescriptors, result = B_OK; } + if (!added) { + // Report hub after children when removing devices + TRACE("reporting hub after children\n"); + if (Device::ReportDevice(supportDescriptors, supportDescriptorCount, + hooks, cookies, added, recursive) == B_OK) + result = B_OK; + } + return result; }