* [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure
@ 2025-02-20 9:52 Wentao Liang
2025-02-20 10:15 ` Greg KH
2025-02-20 10:22 ` Oliver Neukum
0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2025-02-20 9:52 UTC (permalink / raw)
To: gregkh
Cc: stern, christophe.jaillet, mka, make_ruc2021, javier.carrasco,
linux-usb, linux-kernel, Wentao Liang, stable
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.
Fixes: 94fcda1f8ab5 ("usbcore: remove unused argument in autosuspend")
Cc: stable@vger.kernel.org # 2.6.20+
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/usb/core/hub.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 21ac9b464696..f2efdbdd1533 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -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;
--
2.42.0.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure
2025-02-20 9:52 [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure Wentao Liang
@ 2025-02-20 10:15 ` Greg KH
2025-02-20 10:22 ` Oliver Neukum
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-02-20 10:15 UTC (permalink / raw)
To: Wentao Liang
Cc: stern, christophe.jaillet, mka, make_ruc2021, javier.carrasco,
linux-usb, linux-kernel, stable
On Thu, Feb 20, 2025 at 05:52:18PM +0800, Wentao Liang wrote:
> 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.
>
> Fixes: 94fcda1f8ab5 ("usbcore: remove unused argument in autosuspend")
> Cc: stable@vger.kernel.org # 2.6.20+
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> drivers/usb/core/hub.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 21ac9b464696..f2efdbdd1533 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -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?
> + ret = usb_autoresume_device(udev);
> + if (ret < 0)
if (ret) please.
Also, how was this tested? How was it found?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure
2025-02-20 9:52 [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure Wentao Liang
2025-02-20 10:15 ` Greg KH
@ 2025-02-20 10:22 ` Oliver Neukum
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Neukum @ 2025-02-20 10:22 UTC (permalink / raw)
To: Wentao Liang, gregkh
Cc: stern, christophe.jaillet, mka, make_ruc2021, javier.carrasco,
linux-usb, linux-kernel, stable
On 20.02.25 10:52, Wentao Liang wrote:
> In usb_reset_device(), the function continues execution and
> calls usb_autosuspend_device() after usb_autosuspend_device fails.
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-20 10:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 9:52 [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure Wentao Liang
2025-02-20 10:15 ` Greg KH
2025-02-20 10:22 ` Oliver Neukum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox