]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
spi: Add a timeout when waiting for transfers
authorMark Brown <broonie@linaro.org>
Thu, 30 Jan 2014 22:16:41 +0000 (22:16 +0000)
committerMark Brown <broonie@linaro.org>
Mon, 3 Feb 2014 13:04:45 +0000 (13:04 +0000)
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@linaro.org>
drivers/spi/spi.c

index 23756b0f90363c2f776718925cf7fba84d13c4a3..516643d243c6dc3576406bad88feb9009aa604a6 100644 (file)
@@ -594,6 +594,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);
 
@@ -611,7 +612,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);