From patchwork Sat Jul 1 16:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Shurong X-Patchwork-Id: 13299113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C382EB64DD for ; Sat, 1 Jul 2023 16:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229542AbjGAQjd (ORCPT ); Sat, 1 Jul 2023 12:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjGAQjc (ORCPT ); Sat, 1 Jul 2023 12:39:32 -0400 Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9173C1992; Sat, 1 Jul 2023 09:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1688229564; bh=6fCq9djsf59ztW/Td6J0/vZaft/6rDmkJSI0wgjlj6o=; h=From:To:Cc:Subject:Date; b=WIGQhwhx/ycpTHw1CvHqvFSthiNsF71s7Xzu8ZPvxb/hDUNZ+FHxCYrs0gGbIzVgU amPb0EyGdtDHXU3D1j4R5eDi2cWP3J63wrUj0PYcumYuEN145RHY+xVcq3vEUcppE2 p0os9+gYqiyaTg2iI+6TliesHzxzbFNmm0+MOAKs= Received: from KernelDevBox.byted.org ([180.184.51.142]) by newxmesmtplogicsvrsza7-0.qq.com (NewEsmtp) with SMTP id 9D61D215; Sun, 02 Jul 2023 00:39:22 +0800 X-QQ-mid: xmsmtpt1688229562t6mvo2mqs Message-ID: X-QQ-XMAILINFO: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hHCdaPRBwq3WW+NvGbIU= From: Zhang Shurong To: gregkh@linuxfoundation.org Cc: u.kleine-koenig@pengutronix.de, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Shurong Subject: [PATCH v2] usb: r8a66597-hcd: host: fix port index underflow and UBSAN complains Date: Sun, 2 Jul 2023 00:39:20 +0800 X-OQ-MSGID: <20230701163920.1089205-1-zhang_shurong@foxmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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") The changes in this version: - fix some compile error Signed-off-by: Zhang Shurong --- 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..6c597c668364 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c @@ -2141,10 +2141,12 @@ 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; + struct r8a66597_root_hub *rh; + u32 port = wIndex & 0xFF; + port -= (port > 0); + rh = &r8a66597->root_hub[port]; ret = 0; spin_lock_irqsave(&r8a66597->lock, flags);