All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi:fsl-espi: Ignore spurious interrupts
@ 2020-06-01 18:22 minyard
  0 siblings, 0 replies; only message in thread
From: minyard @ 2020-06-01 18:22 UTC (permalink / raw)
  To: Han Xu, linux-spi; +Cc: Corey Minyard

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 --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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-01 18:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 18:22 [PATCH] spi:fsl-espi: Ignore spurious interrupts minyard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.