diff options
author | Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> | 2010-08-28 02:06:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-09-03 20:33:40 -0400 |
commit | 0791971ba8fbc44e4f476079f856335ed45e6324 (patch) | |
tree | 0e5bc00d27fcec07491a5d0c23f2a0a13d6e19c6 /drivers | |
parent | 5b22a32e76defeb573991b301a27d299472c5714 (diff) |
usb: allow drivers to use allocated bandwidth until unbound
When using the remove sysfs file, the device configuration is set to -1
(unconfigured). This eventually unbind drivers with the bandwidth_mutex
held. Some drivers may call functions that hold said mutex, like
usb_reset_device. This is the case for rtl8187, for example. This will
lead to the same process holding the mutex twice, which deadlocks.
Besides, according to Alan Stern:
"The deadlock problem probably could be handled somehow, but there's a
separate issue: Until the usb_disable_device call finishes unbinding
the drivers, the drivers are free to continue using their allocated
bandwidth. We musn't change the bandwidth allocations until after the
unbinding is done. So this patch is indeed necessary."
Unbinding the driver before holding the bandwidth_mutex solves the
problem. If any operation after that fails, drivers are not bound again.
But that would be a problem anyway that the user may solve resetting the
device configuration to one that works, just like he would need to do in
most other failure cases.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/core/message.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index fd4c36ea5e46..844683e50383 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1724,6 +1724,15 @@ free_interfaces: | |||
1724 | if (ret) | 1724 | if (ret) |
1725 | goto free_interfaces; | 1725 | goto free_interfaces; |
1726 | 1726 | ||
1727 | /* if it's already configured, clear out old state first. | ||
1728 | * getting rid of old interfaces means unbinding their drivers. | ||
1729 | */ | ||
1730 | if (dev->state != USB_STATE_ADDRESS) | ||
1731 | usb_disable_device(dev, 1); /* Skip ep0 */ | ||
1732 | |||
1733 | /* Get rid of pending async Set-Config requests for this device */ | ||
1734 | cancel_async_set_config(dev); | ||
1735 | |||
1727 | /* Make sure we have bandwidth (and available HCD resources) for this | 1736 | /* Make sure we have bandwidth (and available HCD resources) for this |
1728 | * configuration. Remove endpoints from the schedule if we're dropping | 1737 | * configuration. Remove endpoints from the schedule if we're dropping |
1729 | * this configuration to set configuration 0. After this point, the | 1738 | * this configuration to set configuration 0. After this point, the |
@@ -1733,20 +1742,11 @@ free_interfaces: | |||
1733 | mutex_lock(&hcd->bandwidth_mutex); | 1742 | mutex_lock(&hcd->bandwidth_mutex); |
1734 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); | 1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); |
1735 | if (ret < 0) { | 1744 | if (ret < 0) { |
1736 | usb_autosuspend_device(dev); | ||
1737 | mutex_unlock(&hcd->bandwidth_mutex); | 1745 | mutex_unlock(&hcd->bandwidth_mutex); |
1746 | usb_autosuspend_device(dev); | ||
1738 | goto free_interfaces; | 1747 | goto free_interfaces; |
1739 | } | 1748 | } |
1740 | 1749 | ||
1741 | /* if it's already configured, clear out old state first. | ||
1742 | * getting rid of old interfaces means unbinding their drivers. | ||
1743 | */ | ||
1744 | if (dev->state != USB_STATE_ADDRESS) | ||
1745 | usb_disable_device(dev, 1); /* Skip ep0 */ | ||
1746 | |||
1747 | /* Get rid of pending async Set-Config requests for this device */ | ||
1748 | cancel_async_set_config(dev); | ||
1749 | |||
1750 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1750 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
1751 | USB_REQ_SET_CONFIGURATION, 0, configuration, 0, | 1751 | USB_REQ_SET_CONFIGURATION, 0, configuration, 0, |
1752 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1752 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
@@ -1761,8 +1761,8 @@ free_interfaces: | |||
1761 | if (!cp) { | 1761 | if (!cp) { |
1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); | 1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); |
1764 | usb_autosuspend_device(dev); | ||
1765 | mutex_unlock(&hcd->bandwidth_mutex); | 1764 | mutex_unlock(&hcd->bandwidth_mutex); |
1765 | usb_autosuspend_device(dev); | ||
1766 | goto free_interfaces; | 1766 | goto free_interfaces; |
1767 | } | 1767 | } |
1768 | mutex_unlock(&hcd->bandwidth_mutex); | 1768 | mutex_unlock(&hcd->bandwidth_mutex); |