diff mbox series

spi:fsl-espi: Ignore spurious interrupts

Message ID 20200601182241.9272-1-minyard@acm.org (mailing list archive)
State New, archived
Headers show
Series spi:fsl-espi: Ignore spurious interrupts | expand

Commit Message

Corey Minyard June 1, 2020, 6:22 p.m. UTC
From: Corey Minyard <cminyard@mvista.com>

If a interrupt comes in for the device and nothing is waiting, it will
crash the system.  Avoid the crash.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
I was working on a system where the firmware seemed to leave the SPI
device in a state where an interrupt was pending.  As soon as interrupts
were enabled the system would crash.

It seems that the interrupt handler will crash if an interrupt comes in
and nothing is pending.  This seems like a bad idea; this patch adds
checking to make sure something is pending before trying to process it.

 drivers/spi/spi-fsl-espi.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index e60581283a24..091f0c681ff6 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -217,6 +217,9 @@  static void fsl_espi_fill_tx_fifo(struct fsl_espi *espi, u32 events)
 	unsigned int tx_left;
 	const void *tx_buf;
 
+	if (!espi->tx_t) /* In case we get a spurious interrupt. */
+		return;
+
 	/* if events is zero transfer has not started and tx fifo is empty */
 	tx_fifo_avail = events ? SPIE_TXCNT(events) :  FSL_ESPI_FIFO_SIZE;
 start:
@@ -274,6 +277,8 @@  static void fsl_espi_read_rx_fifo(struct fsl_espi *espi, u32 events)
 	unsigned int rx_left;
 	void *rx_buf;
 
+	if (!rx_fifo_avail) /* In case we get a spurious interrupt. */
+		return;
 start:
 	rx_left = espi->rx_t->len - espi->rx_pos;
 	rx_buf = espi->rx_t->rx_buf;