Skip to contentSkip to conversation

usb: gadget: r8a66597: fix a loop in set_feature()

PATCH In review Dan Carpenter 3 participants 3 messages Sep 6, 2021 – Sep 7, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: r8a66597: fix a loop in set_feature()

This loop is supposed to loop until if reads something other than CS_IDST or until it times out after 30,000 attempts. But because of the || vs && bug, it will never time out and instead it will loop a minimum of 30,000 times.

This bug is quite old but the code is only used in USB_DEVICE_TEST_MODE so it probably doesn't affect regular usage.

Fixes 96fe53ef5498 ("usb: gadget: r8a66597-udc: add support for TEST_MODE")
---
 drivers/usb/gadget/udc/r8a66597-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/r8a66597-udc.c +1 -1
index 65cae4883454..38e4d6b505a0 100644
@@ -1250,7 +1250,7 @@ static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
 			do {
 				tmp = r8a66597_read(r8a66597, INTSTS0) & CTSQ;
 				udelay(1);
-			} while (tmp != CS_IDST || timeout-- > 0);
+			} while (tmp != CS_IDST && timeout-- > 0);
 
 			if (tmp == CS_IDST)
 				r8a66597_bset(r8a66597,
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 7 lines

From: Dan Carpenter, Sent: Monday, September 6, 2021 6:42 PM

This loop is supposed to loop until if reads something other than CS_IDST or until it times out after 30,000 attempts. But because of the || vs && bug, it will never time out and instead it will loop a minimum of 30,000 times.

Quoted 5 lines

This bug is quite old but the code is only used in USB_DEVICE_TEST_MODE so it probably doesn't affect regular usage.

Fixes 96fe53ef5498 ("usb: gadget: r8a66597-udc: add support for TEST_MODE")

Thank you for the patch!

Best regards,
Yoshihiro Shimoda

Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

This loop is supposed to loop until if reads something other than CS_IDST or until it times out after 30,000 attempts. But because of the || vs && bug, it will never time out and instead it will loop a minimum of 30,000 times.

This bug is quite old but the code is only used in USB_DEVICE_TEST_MODE so it probably doesn't affect regular usage.

Fixes 96fe53ef5498 ("usb: gadget: r8a66597-udc: add support for TEST_MODE")
Signature · 1 line
balbi