Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: cadence: Fix out-of-bounds array access in cdns_mrvl_xspi_setup_clock()

If requested_clk > 128, cdns_mrvl_xspi_setup_clock() iterates over the
entire cdns_mrvl_xspi_clk_div_list array without breaking out early,
causing 'i' to go beyond the array bounds.

Fix that by stopping the loop when it gets to the last entry, clamping
the clock to the minimum 6.25 MHz.

Fixes the following warning with an UBSAN kernel:

vmlinux.o: warning: objtool: cdns_mrvl_xspi_setup_clock: unexpected end of section .text.cdns_mrvl_xspi_setup_clock

Fixes: 26d34fdc4971 ("spi: cadence: Add clock configuration for Marvell xSPI overlay")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503282236.UhfRsF3B-lkp@intel.com/
Link: https://lore.kernel.org/r/gs2ooxfkblnee6cc5yfcxh7nu4wvoqnuv4lrllkhccxgcac2jg@7snmwd73jkhs
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/h6bef6wof6zpjfp3jbhrkigqsnykdfy6j4qmmvb6gsabhianhj@k57a7hwpa3bj
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Josh Poimboeuf and committed by
Mark Brown
7ba0847f 40369bfe

+1 -1
+1 -1
drivers/spi/spi-cadence-xspi.c
··· 432 432 u32 clk_reg; 433 433 bool update_clk = false; 434 434 435 - while (i < ARRAY_SIZE(cdns_mrvl_xspi_clk_div_list)) { 435 + while (i < (ARRAY_SIZE(cdns_mrvl_xspi_clk_div_list) - 1)) { 436 436 clk_val = MRVL_XSPI_CLOCK_DIVIDED( 437 437 cdns_mrvl_xspi_clk_div_list[i]); 438 438 if (clk_val <= requested_clk)