Skip to content

Commit 0df11fa

Browse files
Ma Kegregkh
authored andcommitted
usb: fix reference leak in usb_new_device()
When device_add(&udev->dev) succeeds and a later call fails, usb_new_device() does not properly call device_del(). As comment of device_add() says, 'if device_add() succeeds, you should call device_del() when you want to get rid of it. If device_add() has not succeeded, use only put_device() to drop the reference count'. Found by code review. Cc: stable <[email protected]> Fixes: 9f8b17e ("USB: make usbdevices export their device nodes instead of using a separate class") Signed-off-by: Ma Ke <[email protected]> Reviewed-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 862a9c0 commit 0df11fa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/usb/core/hub.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,13 +2663,13 @@ int usb_new_device(struct usb_device *udev)
26632663
err = sysfs_create_link(&udev->dev.kobj,
26642664
&port_dev->dev.kobj, "port");
26652665
if (err)
2666-
goto fail;
2666+
goto out_del_dev;
26672667

26682668
err = sysfs_create_link(&port_dev->dev.kobj,
26692669
&udev->dev.kobj, "device");
26702670
if (err) {
26712671
sysfs_remove_link(&udev->dev.kobj, "port");
2672-
goto fail;
2672+
goto out_del_dev;
26732673
}
26742674

26752675
if (!test_and_set_bit(port1, hub->child_usage_bits))
@@ -2683,6 +2683,8 @@ int usb_new_device(struct usb_device *udev)
26832683
pm_runtime_put_sync_autosuspend(&udev->dev);
26842684
return err;
26852685

2686+
out_del_dev:
2687+
device_del(&udev->dev);
26862688
fail:
26872689
usb_set_device_state(udev, USB_STATE_NOTATTACHED);
26882690
pm_runtime_disable(&udev->dev);

0 commit comments

Comments
 (0)