Skip to content

Commit 76e51db

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool, spi: amd: Fix out-of-bounds stack access in amd_set_spi_freq()
If speed_hz < AMD_SPI_MIN_HZ, amd_set_spi_freq() iterates over the entire amd_spi_freq 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, so the low speed_hz value gets clamped up to AMD_SPI_MIN_HZ. Fixes the following warning with an UBSAN kernel: drivers/spi/spi-amd.o: error: objtool: amd_set_spi_freq() falls through to next function amd_spi_set_opcode() Fixes: 3fe2612 ("spi: amd: Configure device speed") Reported-by: kernel test robot <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Mark Brown <[email protected]> Cc: Raju Rangoju <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/78fef0f2434f35be9095bcc9ffa23dd8cab667b9.1742852847.git.jpoimboe@kernel.org Closes: https://lore.kernel.org/r/[email protected]/
1 parent a8d39a6 commit 76e51db

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/spi/spi-amd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void amd_set_spi_freq(struct amd_spi *amd_spi, u32 speed_hz)
302302
{
303303
unsigned int i, spd7_val, alt_spd;
304304

305-
for (i = 0; i < ARRAY_SIZE(amd_spi_freq); i++)
305+
for (i = 0; i < ARRAY_SIZE(amd_spi_freq)-1; i++)
306306
if (speed_hz >= amd_spi_freq[i].speed_hz)
307307
break;
308308

0 commit comments

Comments
 (0)