]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: spacemit: add u64 cast to NSEC_PER_SEC to avoid 32-bit overflow
authorGuodong Xu <guodong@riscstar.com>
Tue, 5 May 2026 13:53:34 +0000 (09:53 -0400)
committerMark Brown <broonie@kernel.org>
Tue, 5 May 2026 02:01:22 +0000 (11:01 +0900)
NSEC_PER_SEC expands to the long constant 1000000000L, so NSEC_PER_SEC *
BITS_PER_BYTE (8 * 10^9) overflows on 32-bit-long architectures
before the result reaches the u64 nsec_per_word.

Promote the multiplication to u64 by casting the first operand, which is
NSEC_PER_SEC.

Fixes: efcd8b9d1111 ("spi: spacemit: introduce SpacemiT K1 SPI controller driver")
Suggested-by: Alex Elder <elder@riscstar.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202605050437.RS6mmV2b-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202605050317.Tf9j487w-lkp@intel.com/
Signed-off-by: Guodong Xu <guodong@riscstar.com>
Link: https://patch.msgid.link/20260505-spi-spacemit-k1-fix-overflow-v1-1-77564c2e4e86@riscstar.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-spacemit-k1.c

index 99db429db0b26638da2d987fd37257d2bb4a50d1..215fe66d27b4dbf645814817f143e8affd11dbc6 100644 (file)
@@ -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);
 
        /*