Skip to content

Commit be0b613

Browse files
chleroygregkh
authored andcommitted
spi: fsl-cpm: Check length parity before switching to 16 bit mode
commit 1417927 upstream. Commit fc96ec8 ("spi: fsl-cpm: Use 16 bit mode for large transfers with even size") failed to make sure that the size is really even before switching to 16 bit mode. Until recently the problem went unnoticed because kernfs uses a pre-allocated bounce buffer of size PAGE_SIZE for reading EEPROM. But commit 8ad6249 ("eeprom: at25: convert to spi-mem API") introduced an additional dynamically allocated bounce buffer whose size is exactly the size of the transfer, leading to a buffer overrun in the fsl-cpm driver when that size is odd. Add the missing length parity verification and remain in 8 bit mode when the length is not even. Fixes: fc96ec8 ("spi: fsl-cpm: Use 16 bit mode for large transfers with even size") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/all/638496dd-ec60-4e53-bad7-eb657f67d580@csgroup.eu/ Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Reviewed-by: Sverdlin Alexander <alexander.sverdlin@siemens.com> Link: https://patch.msgid.link/3c4d81c3923c93f95ec56702a454744a4bad3cfc.1763627618.git.christophe.leroy@csgroup.eu Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e086c9 commit be0b613

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/spi/spi-fsl-spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static int fsl_spi_prepare_message(struct spi_controller *ctlr,
335335
if (t->bits_per_word == 16 || t->bits_per_word == 32)
336336
t->bits_per_word = 8; /* pretend its 8 bits */
337337
if (t->bits_per_word == 8 && t->len >= 256 &&
338-
(mpc8xxx_spi->flags & SPI_CPM1))
338+
!(t->len & 1) && (mpc8xxx_spi->flags & SPI_CPM1))
339339
t->bits_per_word = 16;
340340
}
341341
}

0 commit comments

Comments
 (0)