From: Arnd Bergmann <arnd@kernel.org>
To: Mark Brown <broonie@kernel.org>, Yixun Lan <dlan@kernel.org>,
Alex Elder <elder@riscstar.com>,
Guodong Xu <guodong@riscstar.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
linux-spi@vger.kernel.org, linux-riscv@lists.infradead.org,
spacemit@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] spi: spacemit: avoid 32-bit integer overflow warning
Date: Tue, 5 May 2026 19:57:33 +0200 [thread overview]
Message-ID: <20260505175744.900750-1-arnd@kernel.org> (raw)
From: Arnd Bergmann <arnd@arndb.de>
Calculating the bit rate in nanoseconds does not fit into a 32-bit 'int'
type, as gcc-16 points out:
drivers/spi/spi-spacemit-k1.c: In function 'k1_spi_set_speed':
drivers/spi/spi-spacemit-k1.c:393:38: error: integer overflow in expression of type 'long int' results in '-589934592' [-Werror=overflow]
393 | nsec_per_word = NSEC_PER_SEC * BITS_PER_BYTE * drv_data->bytes;
Cast the value to a 64-bit constant to force the longer type for the
calculation.
Fixes: efcd8b9d1111 ("spi: spacemit: introduce SpacemiT K1 SPI controller driver")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
----
There is probably a way to rework the algorithm to avoid both the 64-bit
multiplication and the following division, but I kept this as a minimal
change.
---
drivers/spi/spi-spacemit-k1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-spacemit-k1.c b/drivers/spi/spi-spacemit-k1.c
index 99db429db0b2..215fe66d27b4 100644
--- a/drivers/spi/spi-spacemit-k1.c
+++ b/drivers/spi/spi-spacemit-k1.c
@@ -390,7 +390,7 @@ static int k1_spi_set_speed(struct k1_spi_driver_data *drv_data,
* ticks_per_word = BITS_PER_BYTE * drv_data->bytes;
* We do the divide last for better accuracy.
*/
- nsec_per_word = NSEC_PER_SEC * BITS_PER_BYTE * drv_data->bytes;
+ nsec_per_word = (u64)NSEC_PER_SEC * BITS_PER_BYTE * drv_data->bytes;
nsec_per_word = DIV_ROUND_UP_ULL(nsec_per_word, drv_data->rate);
/*
--
2.39.5
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2026-05-05 17:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 17:57 Arnd Bergmann [this message]
2026-05-05 18:21 ` [PATCH] spi: spacemit: avoid 32-bit integer overflow warning Alex Elder
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=20260505175744.900750-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=arnd@arndb.de \
--cc=broonie@kernel.org \
--cc=dlan@kernel.org \
--cc=elder@riscstar.com \
--cc=guodong@riscstar.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=spacemit@lists.linux.dev \
/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