diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2008-05-20 16:37:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-05-29 16:59:03 -0400 |
commit | e16362a0c8d90e9adbfe477acbe32b021823fb22 (patch) | |
tree | 688efa40b57e8fdb56335f7c5844492026d090cf /drivers/usb | |
parent | 62d104d0deeabd4148e49eba729d963e740e205f (diff) |
USB: fix possible deadlock involving sysfs attributes
There is a potential deadlock when the usb_generic driver is unbound
from a device. The problem is that generic_disconnect() is called
with the device lock held, and it removes a bunch of device attributes
from sysfs. If a user task happens to be running an attribute method
at the time, the removal will block until the method returns. But at
least one of the attribute methods (the store routine for power/level)
needs to acquire the device lock!
This patch (as1093) eliminates the deadlock by moving the calls to
create and remove the sysfs attributes from the usb_generic driver
into usb_new_device() and usb_disconnect(), where they can be invoked
without holding the device lock.
Besides, the other sysfs attributes are created when the device is
registered and removed when the device is unregistered. So it seems
only fitting for the extra attributes to be created and removed at the
same time.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/core/generic.c | 5 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 9 |
2 files changed, 9 insertions, 5 deletions
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index c1cb94e9f242..7e912f21fd36 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c | |||
@@ -155,9 +155,6 @@ static int generic_probe(struct usb_device *udev) | |||
155 | { | 155 | { |
156 | int err, c; | 156 | int err, c; |
157 | 157 | ||
158 | /* put device-specific files into sysfs */ | ||
159 | usb_create_sysfs_dev_files(udev); | ||
160 | |||
161 | /* Choose and set the configuration. This registers the interfaces | 158 | /* Choose and set the configuration. This registers the interfaces |
162 | * with the driver core and lets interface drivers bind to them. | 159 | * with the driver core and lets interface drivers bind to them. |
163 | */ | 160 | */ |
@@ -189,8 +186,6 @@ static void generic_disconnect(struct usb_device *udev) | |||
189 | * unconfigure the device */ | 186 | * unconfigure the device */ |
190 | if (udev->actconfig) | 187 | if (udev->actconfig) |
191 | usb_set_configuration(udev, -1); | 188 | usb_set_configuration(udev, -1); |
192 | |||
193 | usb_remove_sysfs_dev_files(udev); | ||
194 | } | 189 | } |
195 | 190 | ||
196 | #ifdef CONFIG_PM | 191 | #ifdef CONFIG_PM |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index eb57fcc701d7..1a3d2879bc1d 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1326,6 +1326,12 @@ void usb_disconnect(struct usb_device **pdev) | |||
1326 | 1326 | ||
1327 | usb_unlock_device(udev); | 1327 | usb_unlock_device(udev); |
1328 | 1328 | ||
1329 | /* Remove the device-specific files from sysfs. This must be | ||
1330 | * done with udev unlocked, because some of the attribute | ||
1331 | * routines try to acquire the device lock. | ||
1332 | */ | ||
1333 | usb_remove_sysfs_dev_files(udev); | ||
1334 | |||
1329 | /* Unregister the device. The device driver is responsible | 1335 | /* Unregister the device. The device driver is responsible |
1330 | * for removing the device files from usbfs and sysfs and for | 1336 | * for removing the device files from usbfs and sysfs and for |
1331 | * de-configuring the device. | 1337 | * de-configuring the device. |
@@ -1541,6 +1547,9 @@ int usb_new_device(struct usb_device *udev) | |||
1541 | goto fail; | 1547 | goto fail; |
1542 | } | 1548 | } |
1543 | 1549 | ||
1550 | /* put device-specific files into sysfs */ | ||
1551 | usb_create_sysfs_dev_files(udev); | ||
1552 | |||
1544 | /* Tell the world! */ | 1553 | /* Tell the world! */ |
1545 | announce_device(udev); | 1554 | announce_device(udev); |
1546 | return err; | 1555 | return err; |