Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: r8a66597-hcd: host: fix port index underflow and UBSAN complains
@ 2023-07-01 14:29 Zhang Shurong
  2023-07-01 16:04 ` kernel test robot
  2023-07-01 16:45 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Shurong @ 2023-07-01 14:29 UTC (permalink / raw)
  To: gregkh; +Cc: u.kleine-koenig, linux-usb, linux-kernel, Zhang Shurong

If wIndex is 0 (and it often is), these calculations underflow and
UBSAN complains, here resolve this by not decrementing the index when
it is equal to 0.

Similar commit 85e3990bea49 ("USB: EHCI: avoid undefined pointer
arithmetic and placate UBSAN")

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/usb/host/r8a66597-hcd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 9f4bf8c5f8a5..a65e0d995a4b 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2141,9 +2141,11 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 {
 	struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
 	int ret;
-	int port = (wIndex & 0x00FF) - 1;
-	struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
 	unsigned long flags;
+	u32 port_index = wIndex & 0xFF;
+
+	int port -= (port_index > 0);
+	struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
 
 	ret = 0;
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-01 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-01 14:29 [PATCH] usb: r8a66597-hcd: host: fix port index underflow and UBSAN complains Zhang Shurong
2023-07-01 16:04 ` kernel test robot
2023-07-01 16:45 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox