public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: gregkh@linuxfoundation.org
Cc: stern@rowland.harvard.edu, christophe.jaillet@wanadoo.fr,
	mka@chromium.org, make_ruc2021@163.com,
	javier.carrasco@wolfvision.net, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure
Date: Thu, 20 Feb 2025 17:52:18 +0800	[thread overview]
Message-ID: <20250220095218.970-1-vulab@iscas.ac.cn> (raw)

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


             reply	other threads:[~2025-02-20  9:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20  9:52 Wentao Liang [this message]
2025-02-20 10:15 ` [PATCH] usb: core: Add error handling in usb_reset_device for autoresume failure Greg KH
2025-02-20 10:22 ` Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250220095218.970-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=gregkh@linuxfoundation.org \
    --cc=javier.carrasco@wolfvision.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=make_ruc2021@163.com \
    --cc=mka@chromium.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox