diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2014-05-20 21:08:07 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-05-27 19:28:03 -0400 |
commit | 600856c231ccb0cbf8afcf09066a8ab2a93ab03d (patch) | |
tree | aa8e9074adccb30ecbd6ac8aa2dce377e0c5a834 /drivers/usb | |
parent | 342a74934197386e065e8ef00014e6f0cb5effe6 (diff) |
USB: mutual exclusion for resetting a hub and power-managing a port
The USB core doesn't properly handle mutual exclusion between
resetting a hub and changing the power states of the hub's ports. We
need to avoid sending port-power requests to the hub while it is being
reset, because such requests cannot succeed.
This patch fixes the problem by keeping track of when a reset is in
progress. At such times, attempts to suspend (power-off) a port will
fail immediately with -EBUSY, and calls to usb_port_runtime_resume()
will update the power_is_on flag and return immediately. When the
reset is complete, hub_activate() will automatically restore each port
to the proper power state.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/core/hub.c | 12 | ||||
-rw-r--r-- | drivers/usb/core/hub.h | 1 | ||||
-rw-r--r-- | drivers/usb/core/port.c | 6 |
3 files changed, 19 insertions, 0 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 726fa072c3fe..5f43c22ba787 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1276,12 +1276,22 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) | |||
1276 | flush_work(&hub->tt.clear_work); | 1276 | flush_work(&hub->tt.clear_work); |
1277 | } | 1277 | } |
1278 | 1278 | ||
1279 | static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) | ||
1280 | { | ||
1281 | int i; | ||
1282 | |||
1283 | for (i = 0; i < hub->hdev->maxchild; ++i) | ||
1284 | pm_runtime_barrier(&hub->ports[i]->dev); | ||
1285 | } | ||
1286 | |||
1279 | /* caller has locked the hub device */ | 1287 | /* caller has locked the hub device */ |
1280 | static int hub_pre_reset(struct usb_interface *intf) | 1288 | static int hub_pre_reset(struct usb_interface *intf) |
1281 | { | 1289 | { |
1282 | struct usb_hub *hub = usb_get_intfdata(intf); | 1290 | struct usb_hub *hub = usb_get_intfdata(intf); |
1283 | 1291 | ||
1284 | hub_quiesce(hub, HUB_PRE_RESET); | 1292 | hub_quiesce(hub, HUB_PRE_RESET); |
1293 | hub->in_reset = 1; | ||
1294 | hub_pm_barrier_for_all_ports(hub); | ||
1285 | return 0; | 1295 | return 0; |
1286 | } | 1296 | } |
1287 | 1297 | ||
@@ -1290,6 +1300,8 @@ static int hub_post_reset(struct usb_interface *intf) | |||
1290 | { | 1300 | { |
1291 | struct usb_hub *hub = usb_get_intfdata(intf); | 1301 | struct usb_hub *hub = usb_get_intfdata(intf); |
1292 | 1302 | ||
1303 | hub->in_reset = 0; | ||
1304 | hub_pm_barrier_for_all_ports(hub); | ||
1293 | hub_activate(hub, HUB_POST_RESET); | 1305 | hub_activate(hub, HUB_POST_RESET); |
1294 | return 0; | 1306 | return 0; |
1295 | } | 1307 | } |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 33bcb2c6f90a..f9b521e60128 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -66,6 +66,7 @@ struct usb_hub { | |||
66 | unsigned limited_power:1; | 66 | unsigned limited_power:1; |
67 | unsigned quiescing:1; | 67 | unsigned quiescing:1; |
68 | unsigned disconnected:1; | 68 | unsigned disconnected:1; |
69 | unsigned in_reset:1; | ||
69 | 70 | ||
70 | unsigned quirk_check_port_auto_suspend:1; | 71 | unsigned quirk_check_port_auto_suspend:1; |
71 | 72 | ||
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 51542f852393..37647e080599 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c | |||
@@ -81,6 +81,10 @@ static int usb_port_runtime_resume(struct device *dev) | |||
81 | 81 | ||
82 | if (!hub) | 82 | if (!hub) |
83 | return -EINVAL; | 83 | return -EINVAL; |
84 | if (hub->in_reset) { | ||
85 | port_dev->power_is_on = 1; | ||
86 | return 0; | ||
87 | } | ||
84 | 88 | ||
85 | usb_autopm_get_interface(intf); | 89 | usb_autopm_get_interface(intf); |
86 | set_bit(port1, hub->busy_bits); | 90 | set_bit(port1, hub->busy_bits); |
@@ -117,6 +121,8 @@ static int usb_port_runtime_suspend(struct device *dev) | |||
117 | 121 | ||
118 | if (!hub) | 122 | if (!hub) |
119 | return -EINVAL; | 123 | return -EINVAL; |
124 | if (hub->in_reset) | ||
125 | return -EBUSY; | ||
120 | 126 | ||
121 | if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) | 127 | if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) |
122 | == PM_QOS_FLAGS_ALL) | 128 | == PM_QOS_FLAGS_ALL) |