aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/core/driver.c')
-rw-r--r--drivers/usb/core/driver.c121
1 files changed, 80 insertions, 41 deletions
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index ab90a0156828..888881e5f292 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -312,9 +312,9 @@ static int usb_probe_interface(struct device *dev)
312 return error; 312 return error;
313 } 313 }
314 314
315 id = usb_match_id(intf, driver->id_table); 315 id = usb_match_dynamic_id(intf, driver);
316 if (!id) 316 if (!id)
317 id = usb_match_dynamic_id(intf, driver); 317 id = usb_match_id(intf, driver->id_table);
318 if (!id) 318 if (!id)
319 return error; 319 return error;
320 320
@@ -400,8 +400,9 @@ static int usb_unbind_interface(struct device *dev)
400{ 400{
401 struct usb_driver *driver = to_usb_driver(dev->driver); 401 struct usb_driver *driver = to_usb_driver(dev->driver);
402 struct usb_interface *intf = to_usb_interface(dev); 402 struct usb_interface *intf = to_usb_interface(dev);
403 struct usb_host_endpoint *ep, **eps = NULL;
403 struct usb_device *udev; 404 struct usb_device *udev;
404 int error, r, lpm_disable_error; 405 int i, j, error, r, lpm_disable_error;
405 406
406 intf->condition = USB_INTERFACE_UNBINDING; 407 intf->condition = USB_INTERFACE_UNBINDING;
407 408
@@ -425,6 +426,26 @@ static int usb_unbind_interface(struct device *dev)
425 driver->disconnect(intf); 426 driver->disconnect(intf);
426 usb_cancel_queued_reset(intf); 427 usb_cancel_queued_reset(intf);
427 428
429 /* Free streams */
430 for (i = 0, j = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
431 ep = &intf->cur_altsetting->endpoint[i];
432 if (ep->streams == 0)
433 continue;
434 if (j == 0) {
435 eps = kmalloc(USB_MAXENDPOINTS * sizeof(void *),
436 GFP_KERNEL);
437 if (!eps) {
438 dev_warn(dev, "oom, leaking streams\n");
439 break;
440 }
441 }
442 eps[j++] = ep;
443 }
444 if (j) {
445 usb_free_streams(intf, eps, j, GFP_KERNEL);
446 kfree(eps);
447 }
448
428 /* Reset other interface state. 449 /* Reset other interface state.
429 * We cannot do a Set-Interface if the device is suspended or 450 * We cannot do a Set-Interface if the device is suspended or
430 * if it is prepared for a system sleep (since installing a new 451 * if it is prepared for a system sleep (since installing a new
@@ -990,8 +1011,7 @@ EXPORT_SYMBOL_GPL(usb_deregister);
990 * it doesn't support pre_reset/post_reset/reset_resume or 1011 * it doesn't support pre_reset/post_reset/reset_resume or
991 * because it doesn't support suspend/resume. 1012 * because it doesn't support suspend/resume.
992 * 1013 *
993 * 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.
994 * and not @intf->dev.sem.
995 */ 1015 */
996void usb_forced_unbind_intf(struct usb_interface *intf) 1016void usb_forced_unbind_intf(struct usb_interface *intf)
997{ 1017{
@@ -1004,16 +1024,37 @@ void usb_forced_unbind_intf(struct usb_interface *intf)
1004 intf->needs_binding = 1; 1024 intf->needs_binding = 1;
1005} 1025}
1006 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
1007/* Delayed forced unbinding of a USB interface driver and scan 1049/* Delayed forced unbinding of a USB interface driver and scan
1008 * for rebinding. 1050 * for rebinding.
1009 * 1051 *
1010 * 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.
1011 * and not @intf->dev.sem.
1012 * 1053 *
1013 * 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
1014 * progress and the PM "complete" callback hasn't occurred yet. 1055 * progress and the PM "complete" callback hasn't occurred yet.
1015 */ 1056 */
1016void usb_rebind_intf(struct usb_interface *intf) 1057static void usb_rebind_intf(struct usb_interface *intf)
1017{ 1058{
1018 int rc; 1059 int rc;
1019 1060
@@ -1030,68 +1071,66 @@ void usb_rebind_intf(struct usb_interface *intf)
1030 } 1071 }
1031} 1072}
1032 1073
1033#ifdef CONFIG_PM 1074/*
1034 1075 * Rebind drivers to @udev's marked interfaces. These interfaces have
1035/* Unbind drivers for @udev's interfaces that don't support suspend/resume 1076 * the needs_binding flag set.
1036 * There is no check for reset_resume here because it can be determined
1037 * only during resume whether reset_resume is needed.
1038 * 1077 *
1039 * The caller must hold @udev's device lock. 1078 * The caller must hold @udev's device lock.
1040 */ 1079 */
1041static void unbind_no_pm_drivers_interfaces(struct usb_device *udev) 1080static void rebind_marked_interfaces(struct usb_device *udev)
1042{ 1081{
1043 struct usb_host_config *config; 1082 struct usb_host_config *config;
1044 int i; 1083 int i;
1045 struct usb_interface *intf; 1084 struct usb_interface *intf;
1046 struct usb_driver *drv;
1047 1085
1048 config = udev->actconfig; 1086 config = udev->actconfig;
1049 if (config) { 1087 if (config) {
1050 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 1088 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1051 intf = config->interface[i]; 1089 intf = config->interface[i];
1052 1090 if (intf->needs_binding)
1053 if (intf->dev.driver) { 1091 usb_rebind_intf(intf);
1054 drv = to_usb_driver(intf->dev.driver);
1055 if (!drv->suspend || !drv->resume)
1056 usb_forced_unbind_intf(intf);
1057 }
1058 } 1092 }
1059 } 1093 }
1060} 1094}
1061 1095
1062/* Unbind drivers for @udev's interfaces that failed to support reset-resume. 1096/*
1063 * 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.
1064 * 1100 *
1065 * The caller must hold @udev's device lock. 1101 * The caller must hold @udev's device lock.
1066 */ 1102 */
1067static void unbind_no_reset_resume_drivers_interfaces(struct usb_device *udev) 1103void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev)
1068{ 1104{
1069 struct usb_host_config *config; 1105 unbind_marked_interfaces(udev);
1070 int i; 1106 rebind_marked_interfaces(udev);
1071 struct usb_interface *intf;
1072
1073 config = udev->actconfig;
1074 if (config) {
1075 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1076 intf = config->interface[i];
1077 if (intf->dev.driver && intf->needs_binding)
1078 usb_forced_unbind_intf(intf);
1079 }
1080 }
1081} 1107}
1082 1108
1083static 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)
1084{ 1118{
1085 struct usb_host_config *config; 1119 struct usb_host_config *config;
1086 int i; 1120 int i;
1087 struct usb_interface *intf; 1121 struct usb_interface *intf;
1122 struct usb_driver *drv;
1088 1123
1089 config = udev->actconfig; 1124 config = udev->actconfig;
1090 if (config) { 1125 if (config) {
1091 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 1126 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
1092 intf = config->interface[i]; 1127 intf = config->interface[i];
1093 if (intf->needs_binding) 1128
1094 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 }
1095 } 1134 }
1096 } 1135 }
1097} 1136}
@@ -1420,7 +1459,7 @@ int usb_resume_complete(struct device *dev)
1420 * whose needs_binding flag is set 1459 * whose needs_binding flag is set
1421 */ 1460 */
1422 if (udev->state != USB_STATE_NOTATTACHED) 1461 if (udev->state != USB_STATE_NOTATTACHED)
1423 do_rebind_interfaces(udev); 1462 rebind_marked_interfaces(udev);
1424 return 0; 1463 return 0;
1425} 1464}
1426 1465
@@ -1442,7 +1481,7 @@ int usb_resume(struct device *dev, pm_message_t msg)
1442 pm_runtime_disable(dev); 1481 pm_runtime_disable(dev);
1443 pm_runtime_set_active(dev); 1482 pm_runtime_set_active(dev);
1444 pm_runtime_enable(dev); 1483 pm_runtime_enable(dev);
1445 unbind_no_reset_resume_drivers_interfaces(udev); 1484 unbind_marked_interfaces(udev);
1446 } 1485 }
1447 1486
1448 /* Avoid PM error messages for devices disconnected while suspended 1487 /* Avoid PM error messages for devices disconnected while suspended