Skip to content

Commit ca5cbc8

Browse files
AlanSterngregkh
authored andcommitted
USB: hub: fix up early-exit pathway in hub_activate
The early-exit pathway in hub_activate, added by commit e50293e ("USB: fix invalid memory access in hub_activate()") needs improvement. It duplicates code that is already present at the end of the subroutine, and it neglects to undo the effect of a usb_autopm_get_interface_no_resume() call. This patch fixes both problems by making the early-exit pathway jump directly to the end of the subroutine. It simplifies the code at the end by merging two conditionals that actually test the same condition although they appear different: If type < HUB_INIT3 then type must be either HUB_INIT2 or HUB_INIT, and it can't be HUB_INIT because in that case the subroutine would have exited earlier. Signed-off-by: Alan Stern <[email protected]> CC: <[email protected]> #4.4+ Reviewed-by: Viresh Kumar <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6bb47e8 commit ca5cbc8

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/usb/core/hub.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
10551055
device_lock(hub->intfdev);
10561056

10571057
/* Was the hub disconnected while we were waiting? */
1058-
if (hub->disconnected) {
1059-
device_unlock(hub->intfdev);
1060-
kref_put(&hub->kref, hub_release);
1061-
return;
1062-
}
1058+
if (hub->disconnected)
1059+
goto disconnected;
10631060
if (type == HUB_INIT2)
10641061
goto init2;
10651062
goto init3;
@@ -1281,12 +1278,12 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
12811278
/* Scan all ports that need attention */
12821279
kick_hub_wq(hub);
12831280

1284-
/* Allow autosuspend if it was suppressed */
1285-
if (type <= HUB_INIT3)
1281+
if (type == HUB_INIT2 || type == HUB_INIT3) {
1282+
/* Allow autosuspend if it was suppressed */
1283+
disconnected:
12861284
usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1287-
1288-
if (type == HUB_INIT2 || type == HUB_INIT3)
12891285
device_unlock(hub->intfdev);
1286+
}
12901287

12911288
kref_put(&hub->kref, hub_release);
12921289
}

0 commit comments

Comments
 (0)