diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2005-08-10 17:12:31 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 19:28:19 -0400 |
commit | bf193d3cd2a3b73f2df74f57106114867946c09c (patch) | |
tree | cc47350df18dd7bf00a3adb136476e1896f20c19 /drivers/usb/core/hub.c | |
parent | 8b28c7526a302bbfa618f7eab4ef961edd68c9a0 (diff) |
[PATCH] USB: Disconnect children when unbinding the hub driver
This patch (as554) makes the hub driver disconnect any child USB devices
when it is unbound from a hub. Normally this will never happen, but
there are a few oddball ways to unbind the hub driver while leaving the
children intact. For example, the new "unbind" sysfs attribute can be
used for this purpose.
Given that unbinding hubs with children is now safe, the patch also
removes the code that prevented people from doing so using usbfs.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r-- | drivers/usb/core/hub.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 4a4b41f2665a..9f54e8330f78 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -729,10 +729,29 @@ fail: | |||
729 | 729 | ||
730 | static unsigned highspeed_hubs; | 730 | static unsigned highspeed_hubs; |
731 | 731 | ||
732 | /* Called after the hub driver is unbound from a hub with children */ | ||
733 | static void hub_remove_children_work(void *__hub) | ||
734 | { | ||
735 | struct usb_hub *hub = __hub; | ||
736 | struct usb_device *hdev = hub->hdev; | ||
737 | int i; | ||
738 | |||
739 | kfree(hub); | ||
740 | |||
741 | usb_lock_device(hdev); | ||
742 | for (i = 0; i < hdev->maxchild; ++i) { | ||
743 | if (hdev->children[i]) | ||
744 | usb_disconnect(&hdev->children[i]); | ||
745 | } | ||
746 | usb_unlock_device(hdev); | ||
747 | usb_put_dev(hdev); | ||
748 | } | ||
749 | |||
732 | static void hub_disconnect(struct usb_interface *intf) | 750 | static void hub_disconnect(struct usb_interface *intf) |
733 | { | 751 | { |
734 | struct usb_hub *hub = usb_get_intfdata (intf); | 752 | struct usb_hub *hub = usb_get_intfdata (intf); |
735 | struct usb_device *hdev; | 753 | struct usb_device *hdev; |
754 | int n, port1; | ||
736 | 755 | ||
737 | usb_set_intfdata (intf, NULL); | 756 | usb_set_intfdata (intf, NULL); |
738 | hdev = hub->hdev; | 757 | hdev = hub->hdev; |
@@ -760,8 +779,27 @@ static void hub_disconnect(struct usb_interface *intf) | |||
760 | hub->buffer = NULL; | 779 | hub->buffer = NULL; |
761 | } | 780 | } |
762 | 781 | ||
763 | /* Free the memory */ | 782 | /* If there are any children then this is an unbind only, not a |
764 | kfree(hub); | 783 | * physical disconnection. The active ports must be disabled |
784 | * and later on we must call usb_disconnect(). We can't call | ||
785 | * it now because we may not hold the hub's device lock. | ||
786 | */ | ||
787 | n = 0; | ||
788 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | ||
789 | if (hdev->children[port1 - 1]) { | ||
790 | ++n; | ||
791 | hub_port_disable(hub, port1, 1); | ||
792 | } | ||
793 | } | ||
794 | |||
795 | if (n == 0) | ||
796 | kfree(hub); | ||
797 | else { | ||
798 | /* Reuse the hub->leds work_struct for our own purposes */ | ||
799 | INIT_WORK(&hub->leds, hub_remove_children_work, hub); | ||
800 | schedule_work(&hub->leds); | ||
801 | usb_get_dev(hdev); | ||
802 | } | ||
765 | } | 803 | } |
766 | 804 | ||
767 | static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | 805 | static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) |