aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2014-03-12 11:30:38 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-03-17 19:08:27 -0400
commit6aec044cc2f5670cf3b143c151c8be846499bd15 (patch)
treea2d0c9ba0e26e9029a0f62948540799ed53703bf /drivers/usb
parentead5178bf442dbae4008ee54bf4f66a1f6a317c9 (diff)
USB: unbind all interfaces before rebinding any
When a driver doesn't have pre_reset, post_reset, or reset_resume methods, the USB core unbinds that driver when its device undergoes a reset or a reset-resume, and then rebinds it afterward. The existing straightforward implementation can lead to problems, because each interface gets unbound and rebound before the next interface is handled. If a driver claims additional interfaces, the claim may fail because the old binding instance may still own the additional interface when the new instance tries to claim it. This patch fixes the problem by first unbinding all the interfaces that are marked (i.e., their needs_binding flag is set) and then rebinding all of them. The patch also makes the helper functions in driver.c a little more uniform and adjusts some out-of-date comments. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-and-tested-by: "Poulain, Loic" <loic.poulain@intel.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/core/driver.c94
-rw-r--r--drivers/usb/core/hub.c5
-rw-r--r--drivers/usb/core/usb.h2
3 files changed, 60 insertions, 41 deletions
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 08283d40616c..888881e5f292 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1011,8 +1011,7 @@ EXPORT_SYMBOL_GPL(usb_deregister);
1011 * it doesn't support pre_reset/post_reset/reset_resume or 1011 * it doesn't support pre_reset/post_reset/reset_resume or
1012 * because it doesn't support suspend/resume. 1012 * because it doesn't support suspend/resume.
1013 * 1013 *
1014 * The caller must hold @intf's device's lock, but not its pm_mutex 1014 * The caller must hold @intf's device's lock, but not @intf's lock.
1015 * and not @intf->dev.sem.
1016 */ 1015 */
1017void usb_forced_unbind_intf(struct usb_interface *intf) 1016void usb_forced_unbind_intf(struct usb_interface *intf)
1018{ 1017{
@@ -1025,16 +1024,37 @@ void usb_forced_unbind_intf(struct usb_interface *intf)
1025 intf->needs_binding = 1; 1024 intf->needs_binding = 1;
1026} 1025}
1027 1026
1027/*
1028 * Unbind drivers for @udev's marked interfaces. These interfaces have
1029 * the needs_binding flag set, for example by usb_resume_interface().
1030 *
1031 * The caller must hold @udev's device lock.
1032 */
1033static void unbind_marked_interfaces(struct usb_device *udev)
1034{
1035 struct usb_host_config *config;
1036 int i;
1037 struct usb_interface *intf;
1038
1039 config = udev->actconfig;
1040 if (config) {
1041 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1042 intf = config->interface[i];
1043 if (intf->dev.driver && intf->needs_binding)
1044 usb_forced_unbind_intf(intf);
1045 }
1046 }
1047}
1048
1028/* Delayed forced unbinding of a USB interface driver and scan 1049/* Delayed forced unbinding of a USB interface driver and scan
1029 * for rebinding. 1050 * for rebinding.
1030 * 1051 *
1031 * The caller must hold @intf's device's lock, but not its pm_mutex 1052 * The caller must hold @intf's device's lock, but not @intf's lock.
1032 * and not @intf->dev.sem.
1033 * 1053 *
1034 * Note: Rebinds will be skipped if a system sleep transition is in 1054 * Note: Rebinds will be skipped if a system sleep transition is in
1035 * progress and the PM "complete" callback hasn't occurred yet. 1055 * progress and the PM "complete" callback hasn't occurred yet.
1036 */ 1056 */
1037void usb_rebind_intf(struct usb_interface *intf) 1057static void usb_rebind_intf(struct usb_interface *intf)
1038{ 1058{
1039 int rc; 1059 int rc;
1040 1060
@@ -1051,68 +1071,66 @@ void usb_rebind_intf(struct usb_interface *intf)
1051 } 1071 }
1052} 1072}
1053 1073
1054#ifdef CONFIG_PM 1074/*
1055 1075 * Rebind drivers to @udev's marked interfaces. These interfaces have
1056/* Unbind drivers for @udev's interfaces that don't support suspend/resume 1076 * the needs_binding flag set.
1057 * There is no check for reset_resume here because it can be determined
1058 * only during resume whether reset_resume is needed.
1059 * 1077 *
1060 * The caller must hold @udev's device lock. 1078 * The caller must hold @udev's device lock.
1061 */ 1079 */
1062static void unbind_no_pm_drivers_interfaces(struct usb_device *udev) 1080static void rebind_marked_interfaces(struct usb_device *udev)
1063{ 1081{
1064 struct usb_host_config *config; 1082 struct usb_host_config *config;
1065 int i; 1083 int i;
1066 struct usb_interface *intf; 1084 struct usb_interface *intf;
1067 struct usb_driver *drv;
1068 1085
1069 config = udev->actconfig; 1086 config = udev->actconfig;
1070 if (config) { 1087 if (config) {
1071 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 1088 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1072 intf = config->interface[i]; 1089 intf = config->interface[i];
1073 1090 if (intf->needs_binding)
1074 if (intf->dev.driver) { 1091 usb_rebind_intf(intf);
1075 drv = to_usb_driver(intf->dev.driver);
1076 if (!drv->suspend || !drv->resume)
1077 usb_forced_unbind_intf(intf);
1078 }
1079 } 1092 }
1080 } 1093 }
1081} 1094}
1082 1095
1083/* Unbind drivers for @udev's interfaces that failed to support reset-resume. 1096/*
1084 * These interfaces have the needs_binding flag set by usb_resume_interface(). 1097 * Unbind all of @udev's marked interfaces and then rebind all of them.
1098 * This ordering is necessary because some drivers claim several interfaces
1099 * when they are first probed.
1085 * 1100 *
1086 * The caller must hold @udev's device lock. 1101 * The caller must hold @udev's device lock.
1087 */ 1102 */
1088static void unbind_no_reset_resume_drivers_interfaces(struct usb_device *udev) 1103void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev)
1089{ 1104{
1090 struct usb_host_config *config; 1105 unbind_marked_interfaces(udev);
1091 int i; 1106 rebind_marked_interfaces(udev);
1092 struct usb_interface *intf;
1093
1094 config = udev->actconfig;
1095 if (config) {
1096 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1097 intf = config->interface[i];
1098 if (intf->dev.driver && intf->needs_binding)
1099 usb_forced_unbind_intf(intf);
1100 }
1101 }
1102} 1107}
1103 1108
1104static void do_rebind_interfaces(struct usb_device *udev) 1109#ifdef CONFIG_PM
1110
1111/* Unbind drivers for @udev's interfaces that don't support suspend/resume
1112 * There is no check for reset_resume here because it can be determined
1113 * only during resume whether reset_resume is needed.
1114 *
1115 * The caller must hold @udev's device lock.
1116 */
1117static void unbind_no_pm_drivers_interfaces(struct usb_device *udev)
1105{ 1118{
1106 struct usb_host_config *config; 1119 struct usb_host_config *config;
1107 int i; 1120 int i;
1108 struct usb_interface *intf; 1121 struct usb_interface *intf;
1122 struct usb_driver *drv;
1109 1123
1110 config = udev->actconfig; 1124 config = udev->actconfig;
1111 if (config) { 1125 if (config) {
1112 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 1126 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1113 intf = config->interface[i]; 1127 intf = config->interface[i];
1114 if (intf->needs_binding) 1128
1115 usb_rebind_intf(intf); 1129 if (intf->dev.driver) {
1130 drv = to_usb_driver(intf->dev.driver);
1131 if (!drv->suspend || !drv->resume)
1132 usb_forced_unbind_intf(intf);
1133 }
1116 } 1134 }
1117 } 1135 }
1118} 1136}
@@ -1441,7 +1459,7 @@ int usb_resume_complete(struct device *dev)
1441 * whose needs_binding flag is set 1459 * whose needs_binding flag is set
1442 */ 1460 */
1443 if (udev->state != USB_STATE_NOTATTACHED) 1461 if (udev->state != USB_STATE_NOTATTACHED)
1444 do_rebind_interfaces(udev); 1462 rebind_marked_interfaces(udev);
1445 return 0; 1463 return 0;
1446} 1464}
1447 1465
@@ -1463,7 +1481,7 @@ int usb_resume(struct device *dev, pm_message_t msg)
1463 pm_runtime_disable(dev); 1481 pm_runtime_disable(dev);
1464 pm_runtime_set_active(dev); 1482 pm_runtime_set_active(dev);
1465 pm_runtime_enable(dev); 1483 pm_runtime_enable(dev);
1466 unbind_no_reset_resume_drivers_interfaces(udev); 1484 unbind_marked_interfaces(udev);
1467 } 1485 }
1468 1486
1469 /* Avoid PM error messages for devices disconnected while suspended 1487 /* Avoid PM error messages for devices disconnected while suspended
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 5da5394127e9..2d74dfb9c989 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5380,10 +5380,11 @@ int usb_reset_device(struct usb_device *udev)
5380 else if (cintf->condition == 5380 else if (cintf->condition ==
5381 USB_INTERFACE_BOUND) 5381 USB_INTERFACE_BOUND)
5382 rebind = 1; 5382 rebind = 1;
5383 if (rebind)
5384 cintf->needs_binding = 1;
5383 } 5385 }
5384 if (ret == 0 && rebind)
5385 usb_rebind_intf(cintf);
5386 } 5386 }
5387 usb_unbind_and_rebind_marked_interfaces(udev);
5387 } 5388 }
5388 5389
5389 usb_autosuspend_device(udev); 5390 usb_autosuspend_device(udev);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 823857767a16..0923add72b59 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -55,7 +55,7 @@ extern int usb_match_one_id_intf(struct usb_device *dev,
55extern int usb_match_device(struct usb_device *dev, 55extern int usb_match_device(struct usb_device *dev,
56 const struct usb_device_id *id); 56 const struct usb_device_id *id);
57extern void usb_forced_unbind_intf(struct usb_interface *intf); 57extern void usb_forced_unbind_intf(struct usb_interface *intf);
58extern void usb_rebind_intf(struct usb_interface *intf); 58extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
59 59
60extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port, 60extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port,
61 struct dev_state *owner); 61 struct dev_state *owner);