Commit 6be871d5 authored by Mark Brown's avatar Mark Brown

spi: use 'time_left' instead of 'timeout' with

Merge series from Wolfram Sang <wsa+renesas@sang-engineering.com>:

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_*() functions causing patterns like:

        timeout = wait_for_completion_timeout(...)
        if (!timeout) return -ETIMEDOUT;

with all kinds of permutations. Use 'time_left' as a variable to make the code
obvious and self explaining.

This is part of a tree-wide series. The rest of the patches can be found here
(some parts may still be WIP):

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/time_left

Because these patches are generated, I audit them before sending. This is why I
will send series step by step. Build bot is happy with these patches, though.
No functional changes intended.
parents 78d94353 594aa75d
...@@ -339,7 +339,7 @@ static irqreturn_t a3700_spi_interrupt(int irq, void *dev_id) ...@@ -339,7 +339,7 @@ static irqreturn_t a3700_spi_interrupt(int irq, void *dev_id)
static bool a3700_spi_wait_completion(struct spi_device *spi) static bool a3700_spi_wait_completion(struct spi_device *spi)
{ {
struct a3700_spi *a3700_spi; struct a3700_spi *a3700_spi;
unsigned int timeout; unsigned long time_left;
unsigned int ctrl_reg; unsigned int ctrl_reg;
unsigned long timeout_jiffies; unsigned long timeout_jiffies;
...@@ -361,12 +361,12 @@ static bool a3700_spi_wait_completion(struct spi_device *spi) ...@@ -361,12 +361,12 @@ static bool a3700_spi_wait_completion(struct spi_device *spi)
a3700_spi->wait_mask); a3700_spi->wait_mask);
timeout_jiffies = msecs_to_jiffies(A3700_SPI_TIMEOUT); timeout_jiffies = msecs_to_jiffies(A3700_SPI_TIMEOUT);
timeout = wait_for_completion_timeout(&a3700_spi->done, time_left = wait_for_completion_timeout(&a3700_spi->done,
timeout_jiffies); timeout_jiffies);
a3700_spi->wait_mask = 0; a3700_spi->wait_mask = 0;
if (timeout) if (time_left)
return true; return true;
/* there might be the case that right after we checked the /* there might be the case that right after we checked the
......
...@@ -553,7 +553,7 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, ...@@ -553,7 +553,7 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
{ {
struct dma_async_tx_descriptor *desc_tx, *desc_rx; struct dma_async_tx_descriptor *desc_tx, *desc_rx;
unsigned long transfer_timeout; unsigned long transfer_timeout;
unsigned long timeout; unsigned long time_left;
struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg; struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
int ret; int ret;
...@@ -594,9 +594,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, ...@@ -594,9 +594,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
transfer->len); transfer->len);
/* Wait eDMA to finish the data transfer.*/ /* Wait eDMA to finish the data transfer.*/
timeout = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion, time_left = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion,
transfer_timeout); transfer_timeout);
if (!timeout) { if (!time_left) {
dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n"); dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n");
dmaengine_terminate_all(controller->dma_tx); dmaengine_terminate_all(controller->dma_tx);
dmaengine_terminate_all(controller->dma_rx); dmaengine_terminate_all(controller->dma_rx);
...@@ -604,9 +604,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, ...@@ -604,9 +604,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
return -ETIMEDOUT; return -ETIMEDOUT;
} }
timeout = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion, time_left = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion,
transfer_timeout); transfer_timeout);
if (!timeout) { if (!time_left) {
dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n"); dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n");
dmaengine_terminate_all(controller->dma_tx); dmaengine_terminate_all(controller->dma_tx);
dmaengine_terminate_all(controller->dma_rx); dmaengine_terminate_all(controller->dma_rx);
......
...@@ -1405,7 +1405,7 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, ...@@ -1405,7 +1405,7 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
{ {
struct dma_async_tx_descriptor *desc_tx, *desc_rx; struct dma_async_tx_descriptor *desc_tx, *desc_rx;
unsigned long transfer_timeout; unsigned long transfer_timeout;
unsigned long timeout; unsigned long time_left;
struct spi_controller *controller = spi_imx->controller; struct spi_controller *controller = spi_imx->controller;
struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg; struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
struct scatterlist *last_sg = sg_last(rx->sgl, rx->nents); struct scatterlist *last_sg = sg_last(rx->sgl, rx->nents);
...@@ -1471,18 +1471,18 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, ...@@ -1471,18 +1471,18 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len); transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len);
/* Wait SDMA to finish the data transfer.*/ /* Wait SDMA to finish the data transfer.*/
timeout = wait_for_completion_timeout(&spi_imx->dma_tx_completion, time_left = wait_for_completion_timeout(&spi_imx->dma_tx_completion,
transfer_timeout); transfer_timeout);
if (!timeout) { if (!time_left) {
dev_err(spi_imx->dev, "I/O Error in DMA TX\n"); dev_err(spi_imx->dev, "I/O Error in DMA TX\n");
dmaengine_terminate_all(controller->dma_tx); dmaengine_terminate_all(controller->dma_tx);
dmaengine_terminate_all(controller->dma_rx); dmaengine_terminate_all(controller->dma_rx);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
timeout = wait_for_completion_timeout(&spi_imx->dma_rx_completion, time_left = wait_for_completion_timeout(&spi_imx->dma_rx_completion,
transfer_timeout); transfer_timeout);
if (!timeout) { if (!time_left) {
dev_err(&controller->dev, "I/O Error in DMA RX\n"); dev_err(&controller->dev, "I/O Error in DMA RX\n");
spi_imx->devtype_data->reset(spi_imx); spi_imx->devtype_data->reset(spi_imx);
dmaengine_terminate_all(controller->dma_rx); dmaengine_terminate_all(controller->dma_rx);
...@@ -1501,7 +1501,7 @@ static int spi_imx_pio_transfer(struct spi_device *spi, ...@@ -1501,7 +1501,7 @@ static int spi_imx_pio_transfer(struct spi_device *spi,
{ {
struct spi_imx_data *spi_imx = spi_controller_get_devdata(spi->controller); struct spi_imx_data *spi_imx = spi_controller_get_devdata(spi->controller);
unsigned long transfer_timeout; unsigned long transfer_timeout;
unsigned long timeout; unsigned long time_left;
spi_imx->tx_buf = transfer->tx_buf; spi_imx->tx_buf = transfer->tx_buf;
spi_imx->rx_buf = transfer->rx_buf; spi_imx->rx_buf = transfer->rx_buf;
...@@ -1517,9 +1517,9 @@ static int spi_imx_pio_transfer(struct spi_device *spi, ...@@ -1517,9 +1517,9 @@ static int spi_imx_pio_transfer(struct spi_device *spi,
transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len); transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len);
timeout = wait_for_completion_timeout(&spi_imx->xfer_done, time_left = wait_for_completion_timeout(&spi_imx->xfer_done,
transfer_timeout); transfer_timeout);
if (!timeout) { if (!time_left) {
dev_err(&spi->dev, "I/O Error in PIO\n"); dev_err(&spi->dev, "I/O Error in PIO\n");
spi_imx->devtype_data->reset(spi_imx); spi_imx->devtype_data->reset(spi_imx);
return -ETIMEDOUT; return -ETIMEDOUT;
......
...@@ -344,7 +344,7 @@ static int pic32_sqi_one_message(struct spi_controller *host, ...@@ -344,7 +344,7 @@ static int pic32_sqi_one_message(struct spi_controller *host,
struct spi_transfer *xfer; struct spi_transfer *xfer;
struct pic32_sqi *sqi; struct pic32_sqi *sqi;
int ret = 0, mode; int ret = 0, mode;
unsigned long timeout; unsigned long time_left;
u32 val; u32 val;
sqi = spi_controller_get_devdata(host); sqi = spi_controller_get_devdata(host);
...@@ -410,8 +410,8 @@ static int pic32_sqi_one_message(struct spi_controller *host, ...@@ -410,8 +410,8 @@ static int pic32_sqi_one_message(struct spi_controller *host,
writel(val, sqi->regs + PESQI_BD_CTRL_REG); writel(val, sqi->regs + PESQI_BD_CTRL_REG);
/* wait for xfer completion */ /* wait for xfer completion */
timeout = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ); time_left = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ);
if (timeout == 0) { if (time_left == 0) {
dev_err(&sqi->host->dev, "wait timedout/interrupted\n"); dev_err(&sqi->host->dev, "wait timedout/interrupted\n");
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
msg->status = ret; msg->status = ret;
......
...@@ -498,7 +498,7 @@ static int pic32_spi_one_transfer(struct spi_controller *host, ...@@ -498,7 +498,7 @@ static int pic32_spi_one_transfer(struct spi_controller *host,
{ {
struct pic32_spi *pic32s; struct pic32_spi *pic32s;
bool dma_issued = false; bool dma_issued = false;
unsigned long timeout; unsigned long time_left;
int ret; int ret;
pic32s = spi_controller_get_devdata(host); pic32s = spi_controller_get_devdata(host);
...@@ -545,8 +545,8 @@ static int pic32_spi_one_transfer(struct spi_controller *host, ...@@ -545,8 +545,8 @@ static int pic32_spi_one_transfer(struct spi_controller *host,
} }
/* wait for completion */ /* wait for completion */
timeout = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ); time_left = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ);
if (timeout == 0) { if (time_left == 0) {
dev_err(&spi->dev, "wait error/timedout\n"); dev_err(&spi->dev, "wait error/timedout\n");
if (dma_issued) { if (dma_issued) {
dmaengine_terminate_all(host->dma_rx); dmaengine_terminate_all(host->dma_rx);
......
...@@ -206,7 +206,8 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, ...@@ -206,7 +206,8 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,
struct spi_transfer *tfr) struct spi_transfer *tfr)
{ {
struct sun4i_spi *sspi = spi_controller_get_devdata(host); struct sun4i_spi *sspi = spi_controller_get_devdata(host);
unsigned int mclk_rate, div, timeout; unsigned int mclk_rate, div;
unsigned long time_left;
unsigned int start, end, tx_time; unsigned int start, end, tx_time;
unsigned int tx_len = 0; unsigned int tx_len = 0;
int ret = 0; int ret = 0;
...@@ -327,10 +328,10 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, ...@@ -327,10 +328,10 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,
tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U); tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
start = jiffies; start = jiffies;
timeout = wait_for_completion_timeout(&sspi->done, time_left = wait_for_completion_timeout(&sspi->done,
msecs_to_jiffies(tx_time)); msecs_to_jiffies(tx_time));
end = jiffies; end = jiffies;
if (!timeout) { if (!time_left) {
dev_warn(&host->dev, dev_warn(&host->dev,
"%s: timeout transferring %u bytes@%iHz for %i(%i)ms", "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
dev_name(&spi->dev), tfr->len, tfr->speed_hz, dev_name(&spi->dev), tfr->len, tfr->speed_hz,
......
...@@ -277,7 +277,8 @@ static int sun6i_spi_transfer_one(struct spi_controller *host, ...@@ -277,7 +277,8 @@ static int sun6i_spi_transfer_one(struct spi_controller *host,
struct spi_transfer *tfr) struct spi_transfer *tfr)
{ {
struct sun6i_spi *sspi = spi_controller_get_devdata(host); struct sun6i_spi *sspi = spi_controller_get_devdata(host);
unsigned int div, div_cdr1, div_cdr2, timeout; unsigned int div, div_cdr1, div_cdr2;
unsigned long time_left;
unsigned int start, end, tx_time; unsigned int start, end, tx_time;
unsigned int trig_level; unsigned int trig_level;
unsigned int tx_len = 0, rx_len = 0, nbits = 0; unsigned int tx_len = 0, rx_len = 0, nbits = 0;
...@@ -488,26 +489,26 @@ static int sun6i_spi_transfer_one(struct spi_controller *host, ...@@ -488,26 +489,26 @@ static int sun6i_spi_transfer_one(struct spi_controller *host,
tx_time = spi_controller_xfer_timeout(host, tfr); tx_time = spi_controller_xfer_timeout(host, tfr);
start = jiffies; start = jiffies;
timeout = wait_for_completion_timeout(&sspi->done, time_left = wait_for_completion_timeout(&sspi->done,
msecs_to_jiffies(tx_time)); msecs_to_jiffies(tx_time));
if (!use_dma) { if (!use_dma) {
sun6i_spi_drain_fifo(sspi); sun6i_spi_drain_fifo(sspi);
} else { } else {
if (timeout && rx_len) { if (time_left && rx_len) {
/* /*
* Even though RX on the peripheral side has finished * Even though RX on the peripheral side has finished
* RX DMA might still be in flight * RX DMA might still be in flight
*/ */
timeout = wait_for_completion_timeout(&sspi->dma_rx_done, time_left = wait_for_completion_timeout(&sspi->dma_rx_done,
timeout); time_left);
if (!timeout) if (!time_left)
dev_warn(&host->dev, "RX DMA timeout\n"); dev_warn(&host->dev, "RX DMA timeout\n");
} }
} }
end = jiffies; end = jiffies;
if (!timeout) { if (!time_left) {
dev_warn(&host->dev, dev_warn(&host->dev,
"%s: timeout transferring %u bytes@%iHz for %i(%i)ms", "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
dev_name(&spi->dev), tfr->len, tfr->speed_hz, dev_name(&spi->dev), tfr->len, tfr->speed_hz,
......
...@@ -270,7 +270,7 @@ static int xlp_spi_xfer_block(struct xlp_spi_priv *xs, ...@@ -270,7 +270,7 @@ static int xlp_spi_xfer_block(struct xlp_spi_priv *xs,
const unsigned char *tx_buf, const unsigned char *tx_buf,
unsigned char *rx_buf, int xfer_len, int cmd_cont) unsigned char *rx_buf, int xfer_len, int cmd_cont)
{ {
int timeout; unsigned long time_left;
u32 intr_mask = 0; u32 intr_mask = 0;
xs->tx_buf = tx_buf; xs->tx_buf = tx_buf;
...@@ -299,11 +299,11 @@ static int xlp_spi_xfer_block(struct xlp_spi_priv *xs, ...@@ -299,11 +299,11 @@ static int xlp_spi_xfer_block(struct xlp_spi_priv *xs,
intr_mask |= XLP_SPI_INTR_DONE; intr_mask |= XLP_SPI_INTR_DONE;
xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, intr_mask); xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, intr_mask);
timeout = wait_for_completion_timeout(&xs->done, time_left = wait_for_completion_timeout(&xs->done,
msecs_to_jiffies(1000)); msecs_to_jiffies(1000));
/* Disable interrupts */ /* Disable interrupts */
xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, 0x0); xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, 0x0);
if (!timeout) { if (!time_left) {
dev_err(&xs->dev, "xfer timedout!\n"); dev_err(&xs->dev, "xfer timedout!\n");
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment