Skip to content

Commit 6319a68

Browse files
Nobuteru Hayashibroonie
authored andcommitted
spi/fsl-espi: avoid infinite loops on fsl_espi_cpu_irq()
It brought nearly infinite loops, and was possible to be occurred only if the SPI transaction total size are not alighed with 4. Loops are here at while (tmp--), tmp is unsigned, and set it with minus value. The loops are executed as a result of unexpected RX interrupt occurrence after that. This interrupt may be hardware eratta and is not fixed. Fix mspi->len from minus value to 0 and print warning message. Signed-off-by: Nobuteru Hayashi <hayashi.nbb@ncos.nec.co.jp> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent aa70e56 commit 6319a68

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/spi/spi-fsl-espi.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
544544
if (events & SPIE_NE) {
545545
u32 rx_data, tmp;
546546
u8 rx_data_8;
547+
int rx_nr_bytes = 4;
547548
int ret;
548549

549550
/* Spin until RX is done */
@@ -560,7 +561,14 @@ void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
560561

561562
if (mspi->len >= 4) {
562563
rx_data = mpc8xxx_spi_read_reg(&reg_base->receive);
564+
} else if (mspi->len <= 0) {
565+
dev_err(mspi->dev,
566+
"unexpected RX(SPIE_NE) interrupt occurred,\n"
567+
"(local rxlen %d bytes, reg rxlen %d bytes)\n",
568+
min(4, mspi->len), SPIE_RXCNT(events));
569+
rx_nr_bytes = 0;
563570
} else {
571+
rx_nr_bytes = mspi->len;
564572
tmp = mspi->len;
565573
rx_data = 0;
566574
while (tmp--) {
@@ -571,7 +579,7 @@ void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
571579
rx_data <<= (4 - mspi->len) * 8;
572580
}
573581

574-
mspi->len -= 4;
582+
mspi->len -= rx_nr_bytes;
575583

576584
if (mspi->rx)
577585
mspi->get_rx(rx_data, mspi);

0 commit comments

Comments
 (0)