Skip to content

Commit 45f785a

Browse files
AlanSterngregkh
authored andcommitted
usb: gadget: fix a bug and a WARN_ON in dummy-hcd
commit 5f5610f69be3a925b1f79af27150bb7377bc9ad6 upstream. This patch fixes a NULL pointer dereference and a WARN_ON in dummy-hcd. These things were the result of moving to the UDC core framework, and possibly of changes to that framework. Now unloading a gadget driver causes the UDC to be stopped after the gadget driver is unbound, not before. Therefore the "driver" argument to dummy_udc_stop() can be NULL, so we must not try to print the driver's name without checking first. Also, the UDC framework automatically unregisters the gadget when the UDC is deleted. Therefore a sysfs attribute file attached to the gadget must be removed before the UDC is deleted, not after. Signed-off-by: Alan Stern <[email protected]> Signed-off-by: Felipe Balbi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7661107 commit 45f785a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/usb/gadget/dummy_hcd.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,9 @@ static int dummy_udc_stop(struct usb_gadget *g,
923923
struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
924924
struct dummy *dum = dum_hcd->dum;
925925

926-
dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
927-
driver->driver.name);
926+
if (driver)
927+
dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
928+
driver->driver.name);
928929

929930
dum->driver = NULL;
930931

@@ -1000,8 +1001,8 @@ static int dummy_udc_remove(struct platform_device *pdev)
10001001
{
10011002
struct dummy *dum = platform_get_drvdata(pdev);
10021003

1003-
usb_del_gadget_udc(&dum->gadget);
10041004
device_remove_file(&dum->gadget.dev, &dev_attr_function);
1005+
usb_del_gadget_udc(&dum->gadget);
10051006
return 0;
10061007
}
10071008

0 commit comments

Comments
 (0)