Skip to content

Commit 6e6aa61

Browse files
AlanSterngregkh
authored andcommitted
USB: gadget: dummy-hcd: Fix errors in port-reset handling
Commit c318840 ("USB: Gadget: dummy-hcd: Fix shift-out-of-bounds bug") messed up the way dummy-hcd handles requests to turn on the RESET port feature (I didn't notice that the original switch case ended with a fallthrough). The call to set_link_state() was inadvertently removed, as was the code to set the USB_PORT_STAT_RESET flag when the speed is USB2. In addition, the original code never checked whether the port was connected before handling the port-reset request. There was a check for the port being powered, but it was removed by that commit! In practice this doesn't matter much because the kernel doesn't try to reset disconnected ports, but it's still bad form. This patch fixes these problems by changing the fallthrough to break, adding back in the missing set_link_state() call, setting the port-reset status flag, adding a port-is-connected test, and removing a redundant assignment statement. Fixes: c318840 ("USB: Gadget: dummy-hcd: Fix shift-out-of-bounds bug") CC: <[email protected]> Acked-by: Felipe Balbi <[email protected]> Signed-off-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4e0dcf6 commit 6e6aa61

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/usb/gadget/udc/dummy_hcd.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,17 +2270,20 @@ static int dummy_hub_control(
22702270
}
22712271
fallthrough;
22722272
case USB_PORT_FEAT_RESET:
2273+
if (!(dum_hcd->port_status & USB_PORT_STAT_CONNECTION))
2274+
break;
22732275
/* if it's already enabled, disable */
22742276
if (hcd->speed == HCD_USB3) {
2275-
dum_hcd->port_status = 0;
22762277
dum_hcd->port_status =
22772278
(USB_SS_PORT_STAT_POWER |
22782279
USB_PORT_STAT_CONNECTION |
22792280
USB_PORT_STAT_RESET);
2280-
} else
2281+
} else {
22812282
dum_hcd->port_status &= ~(USB_PORT_STAT_ENABLE
22822283
| USB_PORT_STAT_LOW_SPEED
22832284
| USB_PORT_STAT_HIGH_SPEED);
2285+
dum_hcd->port_status |= USB_PORT_STAT_RESET;
2286+
}
22842287
/*
22852288
* We want to reset device status. All but the
22862289
* Self powered feature
@@ -2292,7 +2295,8 @@ static int dummy_hub_control(
22922295
* interval? Is it still 50msec as for HS?
22932296
*/
22942297
dum_hcd->re_timeout = jiffies + msecs_to_jiffies(50);
2295-
fallthrough;
2298+
set_link_state(dum_hcd);
2299+
break;
22962300
case USB_PORT_FEAT_C_CONNECTION:
22972301
case USB_PORT_FEAT_C_RESET:
22982302
case USB_PORT_FEAT_C_ENABLE:

0 commit comments

Comments
 (0)