linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Ryan Chen <ryan_chen@aspeedtech.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	 Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	 linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH v2] usb: uhci: Work around bogus clang shift overflow warning from DMA_BIT_MASK(64)
Date: Wed, 15 Oct 2025 11:43:09 -0700	[thread overview]
Message-ID: <20251015-usb-uhci-avoid-bogus-clang-shift-warning-v2-1-68532d2f6114@kernel.org> (raw)

After commit 18a9ec886d32 ("usb: uhci: Add Aspeed AST2700 support"),
clang incorrectly warns:

  In file included from drivers/usb/host/uhci-hcd.c:855:
  drivers/usb/host/uhci-platform.c:69:32: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
     69 | static const u64 dma_mask_64 = DMA_BIT_MASK(64);
        |                                ^~~~~~~~~~~~~~~~
  include/linux/dma-mapping.h:93:54: note: expanded from macro 'DMA_BIT_MASK'
     93 | #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
        |                                                      ^ ~~~

clang has a long outstanding and complicated problem [1] with generating
a proper control flow graph at global scope, resulting in it being
unable to understand that this shift can never happen due to the
'n == 64' check.

Restructure the code to only use DMA_BIT_MASK() within
uhci_hcd_platform_probe() (i.e., function scope) to avoid this global
scope issue, similar to the approach of commit 274f2232a94f ("usb: ehci:
Add Aspeed AST2700 support").

Closes: https://github.com/ClangBuiltLinux/linux/issues/2136
Link: https://github.com/ClangBuiltLinux/linux/issues/92 [1]
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Changes in v2:
- Slightly rework solution to follow commit 274f2232a94f ("usb: ehci:
  Add Aspeed AST2700 support") (Alan)
- Adjust message to match
- Apply Alan's Reviewed-by from v1
- Link to v1: https://patch.msgid.link/20251014-usb-uhci-avoid-bogus-clang-shift-warning-v1-1-826585eed055@kernel.org
---
 drivers/usb/host/uhci-platform.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index 37607f985cc0..5e02f2ceafb6 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -65,13 +65,10 @@ static const struct hc_driver uhci_platform_hc_driver = {
 	.hub_control =		uhci_hub_control,
 };
 
-static const u64 dma_mask_32 = DMA_BIT_MASK(32);
-static const u64 dma_mask_64 = DMA_BIT_MASK(64);
-
 static int uhci_hcd_platform_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	const u64 *dma_mask_ptr;
+	bool dma_mask_64 = false;
 	struct usb_hcd *hcd;
 	struct uhci_hcd	*uhci;
 	struct resource *res;
@@ -85,11 +82,11 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
 	 * Since shared usb code relies on it, set it here for now.
 	 * Once we have dma capability bindings this can go away.
 	 */
-	dma_mask_ptr = (u64 *)of_device_get_match_data(&pdev->dev);
-	if (!dma_mask_ptr)
-		dma_mask_ptr = &dma_mask_32;
+	if (of_device_get_match_data(&pdev->dev))
+		dma_mask_64 = true;
 
-	ret = dma_coerce_mask_and_coherent(&pdev->dev, *dma_mask_ptr);
+	ret = dma_coerce_mask_and_coherent(&pdev->dev,
+		dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
 	if (ret)
 		return ret;
 
@@ -200,7 +197,7 @@ static void uhci_hcd_platform_shutdown(struct platform_device *op)
 static const struct of_device_id platform_uhci_ids[] = {
 	{ .compatible = "generic-uhci", },
 	{ .compatible = "platform-uhci", },
-	{ .compatible = "aspeed,ast2700-uhci", .data = &dma_mask_64},
+	{ .compatible = "aspeed,ast2700-uhci", .data = (void *)1 },
 	{}
 };
 MODULE_DEVICE_TABLE(of, platform_uhci_ids);

---
base-commit: 877c80dfbf788e57a3338627899033b7007037ee
change-id: 20251014-usb-uhci-avoid-bogus-clang-shift-warning-a80166a24472

Best regards,
--  
Nathan Chancellor <nathan@kernel.org>


             reply	other threads:[~2025-10-15 18:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 18:43 Nathan Chancellor [this message]
2025-10-16  3:27 ` [PATCH v2] usb: uhci: Work around bogus clang shift overflow warning from DMA_BIT_MASK(64) Ryan Chen

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=20251015-usb-uhci-avoid-bogus-clang-shift-warning-v2-1-68532d2f6114@kernel.org \
    --to=nathan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=ryan_chen@aspeedtech.com \
    --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;
as well as URLs for NNTP newsgroup(s).