Skip to contentSkip to conversation

usb: misc: usbtest: add fix for driver hang

PATCH Superseded Lu Baolu 2 participants 3 messages Aug 10, 2016 – Aug 11, 2016

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH v2 1/1 usb: misc: usbtest: add fix for driver hang

In sg_timeout(), req->status is set to "-ETIMEDOUT" before calling into usb_sg_cancel(). usb_sg_cancel() will do nothing and return directly if req->status has been set to a non-zero value. This will cause driver hang whenever transfer time out is triggered.

This patch fixes this issue. It could be backported to stable kernel with version later than v3.15.

---
v1->v2:
- Set retval to -ETIMEDOUT after timed out
- Removed the kernel log in patch description

 drivers/usb/misc/usbtest.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +4 -3
index 6b978f0..c273e11 100644
@@ -585,7 +585,6 @@ static void sg_timeout(unsigned long _req)
 {
 	struct usb_sg_request	*req = (struct usb_sg_request *) _req;
 
-	req->status = -ETIMEDOUT;
 	usb_sg_cancel(req);
 }
 
@@ -616,8 +615,10 @@ static int perform_sglist(
 		mod_timer(&sg_timer, jiffies +
 				msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
 		usb_sg_wait(req);
-		del_timer_sync(&sg_timer);
-		retval = req->status;
+		if (unlikely(!del_timer_sync(&sg_timer)))
+			retval = -ETIMEDOUT;
+		else
+			retval = req->status;
 
 		/* FIXME check resulting data pattern */
 
Signature · 1 line
2.1.4
Acked-by on v2 1/1
#1 lore raw
Quoted 33 lines · Lu Baolu

In sg_timeout(), req->status is set to "-ETIMEDOUT" before calling into usb_sg_cancel(). usb_sg_cancel() will do nothing and return directly if req->status has been set to a non-zero value. This will cause driver hang whenever transfer time out is triggered.

This patch fixes this issue. It could be backported to stable kernel with version later than v3.15.

---
v1->v2:
- Set retval to -ETIMEDOUT after timed out
- Removed the kernel log in patch description

 drivers/usb/misc/usbtest.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +0 -1
index 6b978f0..c273e11 100644
@@ -585,7 +585,6 @@ static void sg_timeout(unsigned long _req)
 {
 	struct usb_sg_request	*req = (struct usb_sg_request *) _req;
 
-	req->status = -ETIMEDOUT;
 	usb_sg_cancel(req);
 }
 
@@ -616,8 +615,10 @@ static int perform_sglist(
 		mod_timer(&sg_timer, jiffies +

drivers/usb/misc/usbtest.c static int perform_sglist( · line 623

Quoted 10 lines
drivers/usb/misc/usbtest.c +4 -2
 				msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
 		usb_sg_wait(req);
-		del_timer_sync(&sg_timer);
-		retval = req->status;
+		if (unlikely(!del_timer_sync(&sg_timer)))
+			retval = -ETIMEDOUT;
+		else
+			retval = req->status;
 
 		/* FIXME check resulting data pattern */

I wouldn't bother with the "unlikely()" because this isn't a hot path. Aside from that,

Alan Stern

author
#2 lore raw

Hi,

Quoted 44 lines · Alan Stern
Quoted 42 lines · Lu Baolu

In sg_timeout(), req->status is set to "-ETIMEDOUT" before calling into usb_sg_cancel(). usb_sg_cancel() will do nothing and return directly if req->status has been set to a non-zero value. This will cause driver hang whenever transfer time out is triggered.

This patch fixes this issue. It could be backported to stable kernel with version later than v3.15.

---
v1->v2:
- Set retval to -ETIMEDOUT after timed out
- Removed the kernel log in patch description

 drivers/usb/misc/usbtest.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +4 -3
index 6b978f0..c273e11 100644
@@ -585,7 +585,6 @@ static void sg_timeout(unsigned long _req)
 {
 	struct usb_sg_request	*req = (struct usb_sg_request *) _req;
 
-	req->status = -ETIMEDOUT;
 	usb_sg_cancel(req);
 }
 
@@ -616,8 +615,10 @@ static int perform_sglist(
 		mod_timer(&sg_timer, jiffies +
 				msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
 		usb_sg_wait(req);
-		del_timer_sync(&sg_timer);
-		retval = req->status;
+		if (unlikely(!del_timer_sync(&sg_timer)))
+			retval = -ETIMEDOUT;
+		else
+			retval = req->status;
 
Quoted 5 lines

drivers/usb/misc/usbtest.c static int perform_sglist( · line 623

Quoted 1 line
drivers/usb/misc/usbtest.c +0 -0
 		/* FIXME check resulting data pattern */

I wouldn't bother with the "unlikely()" because this isn't a hot path. Aside from that,

Thank you. I will remove "unlikely()" in new version.

Best regards,
Lu Baolu