Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH] spi: Add a timeout when waiting for transfers
@ 2014-01-30 22:38 Mark Brown
       [not found] ` <1391121536-10937-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2014-01-30 22:38 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA
  Cc: linaro-kernel-cunTk1MwBs8s++Sfvej+rw, Mark Brown

From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

Don't wait indefinitely for transfers to complete but time out after 10ms
more than we expect the transfer to take on the wire.

Signed-off-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 7f23cf9afa79..1826a50c2aaf 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -710,6 +710,7 @@ static int spi_transfer_one_message(struct spi_master *master,
 	bool cur_cs = true;
 	bool keep_cs = false;
 	int ret = 0;
+	int ms = 1;
 
 	spi_set_cs(msg->spi, true);
 
@@ -727,7 +728,16 @@ static int spi_transfer_one_message(struct spi_master *master,
 
 		if (ret > 0) {
 			ret = 0;
-			wait_for_completion(&master->xfer_completion);
+			ms = xfer->len * 8 * 1000 / xfer->speed_hz;
+			ms += 10; /* some tolerance */
+
+			ms = wait_for_completion_timeout(&master->xfer_completion,
+							 msecs_to_jiffies(ms));
+		}
+
+		if (ms == 0) {
+			dev_err(&msg->spi->dev, "SPI transfer timed out\n");
+			msg->status = -ETIMEDOUT;
 		}
 
 		trace_spi_transfer_stop(msg, xfer);
-- 
1.9.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-04 17:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-30 22:38 [PATCH] spi: Add a timeout when waiting for transfers Mark Brown
     [not found] ` <1391121536-10937-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-01-31  7:49   ` Geert Uytterhoeven
     [not found]     ` <CAMuHMdUVmL5Zq8AYPVmUyWEBTzokSMV-Xg4uFzpxr7c2uSmU7g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-31 11:49       ` Mark Brown
     [not found]         ` <20140131114935.GA22609-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-31 12:00           ` Geert Uytterhoeven
     [not found]             ` <CAMuHMdXLe+Ot5ntOtUC2Qynid4mv1h+UoitJuDW=Z-iyRKXCdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-31 12:26               ` Mark Brown
     [not found]                 ` <20140131122617.GC22609-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-02-03  8:55                   ` Geert Uytterhoeven
     [not found]                     ` <CAMuHMdXgDAPy4aezxULQsjiRUfyE3F2_NSjuWhBiy119DSXR5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-02-04 17:45                       ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox