usb: core: Add error handling in usb_reset_device for autoresume failure
Subsystems (2)
PATCH 1/1 usb: core: Add error handling in usb_reset_device for autoresume failure
In usb_reset_device(), the function continues execution and calls usb_autosuspend_device() after usb_autosuspend_device fails.
To fix this, add error handling for usb_autoresume_device() and return the error code immediately. This ensures that usb_autosuspend_device() is not called when usb_autoresume_device() fails, maintaining device state consistency.
--- drivers/usb/core/hub.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/core/hub.c +4 -1
@@ -6292,7 +6292,9 @@ int usb_reset_device(struct usb_device *udev) noio_flag =memalloc_noio_save ();/* Prevent autosuspend during the reset */ -usb_autoresume_device (udev); + ret =usb_autoresume_device (udev); +if (ret <0 ) + goto error_autoresume;if (config) {for (i =0 ; i < config->desc.bNumInterfaces; ++i) {
@@ -6341,6 +6343,7 @@ int usb_reset_device(struct usb_device *udev) }usb_autosuspend_device (udev); +error_autoresume:memalloc_noio_restore (noio_flag); udev->reset_in_progress =0 ;return ret;
Signature · 1 line
2.42.0.windows.2
Greg KH
maintainerQuoted 20 lines · Wentao Liang
In
usb_reset_device(), the function continues execution and callsusb_autosuspend_device()afterusb_autosuspend_devicefails.To fix this, add error handling for
usb_autoresume_device()and return the error code immediately. This ensures thatusb_autosuspend_device()is not called whenusb_autoresume_device()fails, maintaining device state consistency.Fixes 94fcda1f8ab5 ("usbcore: remove unused argument in autosuspend")Cc [email protected] # 2.6.20+Signed-off-by Wentao Liang <[email protected]>--- drivers/usb/core/hub.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/core/hub.c +0
-0
drivers/usb/core/hub.c int usb_reset_device(struct usb_device *udev) · line 6295
Quoted 4 lines
drivers/usb/core/hub.c +0
-1@@ -6292,7 +6292,9 @@ int usb_reset_device(struct usb_device *udev) noio_flag =memalloc_noio_save ();/* Prevent autosuspend during the reset */ -usb_autoresume_device (udev);
Have you ever seen this function fail?
drivers/usb/core/hub.c int usb_reset_device(struct usb_device *udev) · line 6296
Quoted 2 lines
drivers/usb/core/hub.c +2
-0+ ret =usb_autoresume_device (udev); +if (ret <0 )
if (ret) please.
Also, how was this tested? How was it found?
thanks,
greg k-h
Quoted 2 lines · Wentao Liang
In
usb_reset_device(), the function continues execution and callsusb_autosuspend_device()afterusb_autosuspend_devicefails.
This can only fail if the device needs to be physically resumed. In that case you called usb_reset_device() while you weren't supposed to. The purpose of the call is to keep the counter elevated in order to disable runtime power management temporarily.
The code is older than helpers to elevate the count. The correct fix would be to use them rather than handle an error that cannot happen.
Regards
Oliver