]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
usb: fix reference leak in usb_new_device()
authorMa Ke <make_ruc2021@163.com>
Wed, 18 Dec 2024 07:13:46 +0000 (15:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jan 2025 16:15:54 +0000 (17:15 +0100)
commit7cdb2d0f1af9ad80c8e6a5c4b05a3621b4ac3aff
treed530baa20796d31db3e443a1942ad9a8aeab553d
parent162428a00a0cd656140f6e74cfbdc3b8132de526
usb: fix reference leak in usb_new_device()

commit 0df11fa8cee5a9cf8753d4e2672bb3667138c652 upstream.

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 <stable@kernel.org>
Fixes: 9f8b17e643fe ("USB: make usbdevices export their device nodes instead of using a separate class")
Signed-off-by: Ma Ke <make_ruc2021@163.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20241218071346.2973980-1-make_ruc2021@163.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hub.c