]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.7.3/usb-hub-fix-up-early-exit-pathway-in-hub_activate.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.7.3 / usb-hub-fix-up-early-exit-pathway-in-hub_activate.patch
1 From ca5cbc8b02f9b21cc8cd1ab36668763ec34f9ee8 Mon Sep 17 00:00:00 2001
2 From: Alan Stern <stern@rowland.harvard.edu>
3 Date: Fri, 5 Aug 2016 11:49:45 -0400
4 Subject: USB: hub: fix up early-exit pathway in hub_activate
5
6 From: Alan Stern <stern@rowland.harvard.edu>
7
8 commit ca5cbc8b02f9b21cc8cd1ab36668763ec34f9ee8 upstream.
9
10 The early-exit pathway in hub_activate, added by commit e50293ef9775
11 ("USB: fix invalid memory access in hub_activate()") needs
12 improvement. It duplicates code that is already present at the end of
13 the subroutine, and it neglects to undo the effect of a
14 usb_autopm_get_interface_no_resume() call.
15
16 This patch fixes both problems by making the early-exit pathway jump
17 directly to the end of the subroutine. It simplifies the code at the
18 end by merging two conditionals that actually test the same condition
19 although they appear different: If type < HUB_INIT3 then type must be
20 either HUB_INIT2 or HUB_INIT, and it can't be HUB_INIT because in that
21 case the subroutine would have exited earlier.
22
23 Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
24 Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27
28 ---
29 drivers/usb/core/hub.c | 15 ++++++---------
30 1 file changed, 6 insertions(+), 9 deletions(-)
31
32 --- a/drivers/usb/core/hub.c
33 +++ b/drivers/usb/core/hub.c
34 @@ -1055,11 +1055,8 @@ static void hub_activate(struct usb_hub
35 device_lock(hub->intfdev);
36
37 /* Was the hub disconnected while we were waiting? */
38 - if (hub->disconnected) {
39 - device_unlock(hub->intfdev);
40 - kref_put(&hub->kref, hub_release);
41 - return;
42 - }
43 + if (hub->disconnected)
44 + goto disconnected;
45 if (type == HUB_INIT2)
46 goto init2;
47 goto init3;
48 @@ -1281,12 +1278,12 @@ static void hub_activate(struct usb_hub
49 /* Scan all ports that need attention */
50 kick_hub_wq(hub);
51
52 - /* Allow autosuspend if it was suppressed */
53 - if (type <= HUB_INIT3)
54 + if (type == HUB_INIT2 || type == HUB_INIT3) {
55 + /* Allow autosuspend if it was suppressed */
56 + disconnected:
57 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
58 -
59 - if (type == HUB_INIT2 || type == HUB_INIT3)
60 device_unlock(hub->intfdev);
61 + }
62
63 kref_put(&hub->kref, hub_release);
64 }