Linux-SPI Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions
@ 2024-04-30 11:41 Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi
  Cc: Wolfram Sang, Chen-Yu Tsai, imx, Jernej Skrabec, linux-arm-kernel,
	linux-kernel, linux-sunxi, Mark Brown, Samuel Holland,
	Sascha Hauer, Shawn Guo

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.

Changes since v1:
* tags added (thanks!)
* white space issue in sun6i driver fixed
* add maintainers to coverletter

Wolfram Sang (8):
  spi: armada-3700: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: fsl-lpspi: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: imx: use 'time_left' variable with wait_for_completion_timeout()
  spi: pic32-sqi: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: pic32: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: sun4i: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: sun6i: use 'time_left' variable with
    wait_for_completion_timeout()
  spi: xlp: use 'time_left' variable with wait_for_completion_timeout()

 drivers/spi/spi-armada-3700.c |  8 ++++----
 drivers/spi/spi-fsl-lpspi.c   | 14 +++++++-------
 drivers/spi/spi-imx.c         | 20 ++++++++++----------
 drivers/spi/spi-pic32-sqi.c   |  6 +++---
 drivers/spi/spi-pic32.c       |  6 +++---
 drivers/spi/spi-sun4i.c       |  9 +++++----
 drivers/spi/spi-sun6i.c       | 17 +++++++++--------
 drivers/spi/spi-xlp.c         |  8 ++++----
 8 files changed, 45 insertions(+), 43 deletions(-)

-- 
2.43.0


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

* [PATCH v2 1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 2/8] spi: fsl-lpspi: " Wolfram Sang
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi; +Cc: Wolfram Sang, Mark Brown, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/spi/spi-armada-3700.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-armada-3700.c b/drivers/spi/spi-armada-3700.c
index 3c9ed412932f..02c1e625742d 100644
--- a/drivers/spi/spi-armada-3700.c
+++ b/drivers/spi/spi-armada-3700.c
@@ -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)
 {
 	struct a3700_spi *a3700_spi;
-	unsigned int timeout;
+	unsigned long time_left;
 	unsigned int ctrl_reg;
 	unsigned long timeout_jiffies;
 
@@ -361,12 +361,12 @@ static bool a3700_spi_wait_completion(struct spi_device *spi)
 		     a3700_spi->wait_mask);
 
 	timeout_jiffies = msecs_to_jiffies(A3700_SPI_TIMEOUT);
-	timeout = wait_for_completion_timeout(&a3700_spi->done,
-					      timeout_jiffies);
+	time_left = wait_for_completion_timeout(&a3700_spi->done,
+						timeout_jiffies);
 
 	a3700_spi->wait_mask = 0;
 
-	if (timeout)
+	if (time_left)
 		return true;
 
 	/* there might be the case that right after we checked the
-- 
2.43.0


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

* [PATCH v2 2/8] spi: fsl-lpspi: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 3/8] spi: imx: " Wolfram Sang
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi; +Cc: Wolfram Sang, Mark Brown, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/spi/spi-fsl-lpspi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 92a662d1b55c..aa5ed254be46 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -553,7 +553,7 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
 {
 	struct dma_async_tx_descriptor *desc_tx, *desc_rx;
 	unsigned long transfer_timeout;
-	unsigned long timeout;
+	unsigned long time_left;
 	struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
 	int ret;
 
@@ -594,9 +594,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
 							       transfer->len);
 
 		/* Wait eDMA to finish the data transfer.*/
-		timeout = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion,
-						      transfer_timeout);
-		if (!timeout) {
+		time_left = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion,
+							transfer_timeout);
+		if (!time_left) {
 			dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n");
 			dmaengine_terminate_all(controller->dma_tx);
 			dmaengine_terminate_all(controller->dma_rx);
@@ -604,9 +604,9 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
 			return -ETIMEDOUT;
 		}
 
-		timeout = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion,
-						      transfer_timeout);
-		if (!timeout) {
+		time_left = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion,
+							transfer_timeout);
+		if (!time_left) {
 			dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n");
 			dmaengine_terminate_all(controller->dma_tx);
 			dmaengine_terminate_all(controller->dma_rx);
-- 
2.43.0


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

* [PATCH v2 3/8] spi: imx: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 2/8] spi: fsl-lpspi: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 4/8] spi: pic32-sqi: " Wolfram Sang
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi
  Cc: Wolfram Sang, Peng Fan, Mark Brown, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, imx, linux-arm-kernel,
	linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/spi/spi-imx.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index c3e5cee18bea..f4006c82f867 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -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;
 	unsigned long transfer_timeout;
-	unsigned long timeout;
+	unsigned long time_left;
 	struct spi_controller *controller = spi_imx->controller;
 	struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
 	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,
 	transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len);
 
 	/* 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);
-	if (!timeout) {
+	if (!time_left) {
 		dev_err(spi_imx->dev, "I/O Error in DMA TX\n");
 		dmaengine_terminate_all(controller->dma_tx);
 		dmaengine_terminate_all(controller->dma_rx);
 		return -ETIMEDOUT;
 	}
 
-	timeout = wait_for_completion_timeout(&spi_imx->dma_rx_completion,
-					      transfer_timeout);
-	if (!timeout) {
+	time_left = wait_for_completion_timeout(&spi_imx->dma_rx_completion,
+						transfer_timeout);
+	if (!time_left) {
 		dev_err(&controller->dev, "I/O Error in DMA RX\n");
 		spi_imx->devtype_data->reset(spi_imx);
 		dmaengine_terminate_all(controller->dma_rx);
@@ -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);
 	unsigned long transfer_timeout;
-	unsigned long timeout;
+	unsigned long time_left;
 
 	spi_imx->tx_buf = transfer->tx_buf;
 	spi_imx->rx_buf = transfer->rx_buf;
@@ -1517,9 +1517,9 @@ static int spi_imx_pio_transfer(struct spi_device *spi,
 
 	transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len);
 
-	timeout = wait_for_completion_timeout(&spi_imx->xfer_done,
-					      transfer_timeout);
-	if (!timeout) {
+	time_left = wait_for_completion_timeout(&spi_imx->xfer_done,
+						transfer_timeout);
+	if (!time_left) {
 		dev_err(&spi->dev, "I/O Error in PIO\n");
 		spi_imx->devtype_data->reset(spi_imx);
 		return -ETIMEDOUT;
-- 
2.43.0


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

* [PATCH v2 4/8] spi: pic32-sqi: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (2 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 3/8] spi: imx: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 5/8] spi: pic32: " Wolfram Sang
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi; +Cc: Wolfram Sang, Mark Brown, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/spi/spi-pic32-sqi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-pic32-sqi.c b/drivers/spi/spi-pic32-sqi.c
index 3f1e5b27776b..0031063a7e25 100644
--- a/drivers/spi/spi-pic32-sqi.c
+++ b/drivers/spi/spi-pic32-sqi.c
@@ -344,7 +344,7 @@ static int pic32_sqi_one_message(struct spi_controller *host,
 	struct spi_transfer *xfer;
 	struct pic32_sqi *sqi;
 	int ret = 0, mode;
-	unsigned long timeout;
+	unsigned long time_left;
 	u32 val;
 
 	sqi = spi_controller_get_devdata(host);
@@ -410,8 +410,8 @@ static int pic32_sqi_one_message(struct spi_controller *host,
 	writel(val, sqi->regs + PESQI_BD_CTRL_REG);
 
 	/* wait for xfer completion */
-	timeout = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ);
-	if (timeout == 0) {
+	time_left = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ);
+	if (time_left == 0) {
 		dev_err(&sqi->host->dev, "wait timedout/interrupted\n");
 		ret = -ETIMEDOUT;
 		msg->status = ret;
-- 
2.43.0


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

* [PATCH v2 5/8] spi: pic32: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (3 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 4/8] spi: pic32-sqi: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 6/8] spi: sun4i: " Wolfram Sang
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi; +Cc: Wolfram Sang, Mark Brown, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/spi/spi-pic32.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-pic32.c b/drivers/spi/spi-pic32.c
index 709edb70ad7d..b8bcc220e96d 100644
--- a/drivers/spi/spi-pic32.c
+++ b/drivers/spi/spi-pic32.c
@@ -498,7 +498,7 @@ static int pic32_spi_one_transfer(struct spi_controller *host,
 {
 	struct pic32_spi *pic32s;
 	bool dma_issued = false;
-	unsigned long timeout;
+	unsigned long time_left;
 	int ret;
 
 	pic32s = spi_controller_get_devdata(host);
@@ -545,8 +545,8 @@ static int pic32_spi_one_transfer(struct spi_controller *host,
 	}
 
 	/* wait for completion */
-	timeout = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ);
-	if (timeout == 0) {
+	time_left = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ);
+	if (time_left == 0) {
 		dev_err(&spi->dev, "wait error/timedout\n");
 		if (dma_issued) {
 			dmaengine_terminate_all(host->dma_rx);
-- 
2.43.0


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

* [PATCH v2 6/8] spi: sun4i: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (4 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 5/8] spi: pic32: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 7/8] spi: sun6i: " Wolfram Sang
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi
  Cc: Wolfram Sang, Jernej Skrabec, Mark Brown, Chen-Yu Tsai,
	Samuel Holland, linux-arm-kernel, linux-sunxi, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 drivers/spi/spi-sun4i.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index 11d8bd27b3e9..2ee6755b43f5 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -206,7 +206,8 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,
 				  struct spi_transfer *tfr)
 {
 	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 tx_len = 0;
 	int ret = 0;
@@ -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);
 	start = jiffies;
-	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(tx_time));
+	time_left = wait_for_completion_timeout(&sspi->done,
+						msecs_to_jiffies(tx_time));
 	end = jiffies;
-	if (!timeout) {
+	if (!time_left) {
 		dev_warn(&host->dev,
 			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
 			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
-- 
2.43.0


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

* [PATCH v2 7/8] spi: sun6i: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (5 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 6/8] spi: sun4i: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-04-30 11:41 ` [PATCH v2 8/8] spi: xlp: " Wolfram Sang
  2024-05-02  3:57 ` [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Mark Brown
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi
  Cc: Wolfram Sang, Jernej Skrabec, Andre Przywara, Mark Brown,
	Chen-Yu Tsai, Samuel Holland, linux-arm-kernel, linux-sunxi,
	linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/spi/spi-sun6i.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
index cd018ea1abf1..5c26bf056293 100644
--- a/drivers/spi/spi-sun6i.c
+++ b/drivers/spi/spi-sun6i.c
@@ -277,7 +277,8 @@ static int sun6i_spi_transfer_one(struct spi_controller *host,
 				  struct spi_transfer *tfr)
 {
 	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 trig_level;
 	unsigned int tx_len = 0, rx_len = 0, nbits = 0;
@@ -488,26 +489,26 @@ static int sun6i_spi_transfer_one(struct spi_controller *host,
 
 	tx_time = spi_controller_xfer_timeout(host, tfr);
 	start = jiffies;
-	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(tx_time));
+	time_left = wait_for_completion_timeout(&sspi->done,
+						msecs_to_jiffies(tx_time));
 
 	if (!use_dma) {
 		sun6i_spi_drain_fifo(sspi);
 	} else {
-		if (timeout && rx_len) {
+		if (time_left && rx_len) {
 			/*
 			 * Even though RX on the peripheral side has finished
 			 * RX DMA might still be in flight
 			 */
-			timeout = wait_for_completion_timeout(&sspi->dma_rx_done,
-							      timeout);
-			if (!timeout)
+			time_left = wait_for_completion_timeout(&sspi->dma_rx_done,
+								time_left);
+			if (!time_left)
 				dev_warn(&host->dev, "RX DMA timeout\n");
 		}
 	}
 
 	end = jiffies;
-	if (!timeout) {
+	if (!time_left) {
 		dev_warn(&host->dev,
 			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
 			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
-- 
2.43.0


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

* [PATCH v2 8/8] spi: xlp: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (6 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 7/8] spi: sun6i: " Wolfram Sang
@ 2024-04-30 11:41 ` Wolfram Sang
  2024-05-02  3:57 ` [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Mark Brown
  8 siblings, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2024-04-30 11:41 UTC (permalink / raw
  To: linux-spi; +Cc: Wolfram Sang, Mark Brown, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() 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
self explaining.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/spi/spi-xlp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-xlp.c b/drivers/spi/spi-xlp.c
index 49302364b7bd..2fec18b68449 100644
--- a/drivers/spi/spi-xlp.c
+++ b/drivers/spi/spi-xlp.c
@@ -270,7 +270,7 @@ static int xlp_spi_xfer_block(struct  xlp_spi_priv *xs,
 		const unsigned char *tx_buf,
 		unsigned char *rx_buf, int xfer_len, int cmd_cont)
 {
-	int timeout;
+	unsigned long time_left;
 	u32 intr_mask = 0;
 
 	xs->tx_buf = tx_buf;
@@ -299,11 +299,11 @@ static int xlp_spi_xfer_block(struct  xlp_spi_priv *xs,
 	intr_mask |= XLP_SPI_INTR_DONE;
 	xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, intr_mask);
 
-	timeout = wait_for_completion_timeout(&xs->done,
-				msecs_to_jiffies(1000));
+	time_left = wait_for_completion_timeout(&xs->done,
+						msecs_to_jiffies(1000));
 	/* Disable interrupts */
 	xlp_spi_reg_write(xs, xs->cs, XLP_SPI_INTR_EN, 0x0);
-	if (!timeout) {
+	if (!time_left) {
 		dev_err(&xs->dev, "xfer timedout!\n");
 		goto out;
 	}
-- 
2.43.0


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

* Re: [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions
  2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
                   ` (7 preceding siblings ...)
  2024-04-30 11:41 ` [PATCH v2 8/8] spi: xlp: " Wolfram Sang
@ 2024-05-02  3:57 ` Mark Brown
  8 siblings, 0 replies; 10+ messages in thread
From: Mark Brown @ 2024-05-02  3:57 UTC (permalink / raw
  To: linux-spi, Wolfram Sang
  Cc: Chen-Yu Tsai, imx, Jernej Skrabec, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland, Sascha Hauer, Shawn Guo

On Tue, 30 Apr 2024 13:41:32 +0200, Wolfram Sang wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout()
      commit: 7dbbbb1206dd0b695b9a76d3b758c8a689f1aa52
[2/8] spi: fsl-lpspi: use 'time_left' variable with wait_for_completion_timeout()
      commit: eef51e99f7b9ecc903a3a9ad9e7ca84dc35c3f52
[3/8] spi: imx: use 'time_left' variable with wait_for_completion_timeout()
      commit: eaeac043ab842d2e84616ff0412eec0121c1758c
[4/8] spi: pic32-sqi: use 'time_left' variable with wait_for_completion_timeout()
      commit: a7c79e50a26cb619400ccc6294dbd7d8c24a0341
[5/8] spi: pic32: use 'time_left' variable with wait_for_completion_timeout()
      commit: e66480aed4a194f278da1e46ec45221b3983216f
[6/8] spi: sun4i: use 'time_left' variable with wait_for_completion_timeout()
      commit: 34bed8a33f3a4f69b0ef584ef49f04a671a4a5c2
[7/8] spi: sun6i: use 'time_left' variable with wait_for_completion_timeout()
      commit: 83a3f1ba60d6e2f73c9dd2627a8ce41867dbc46b
[8/8] spi: xlp: use 'time_left' variable with wait_for_completion_timeout()
      commit: 594aa75d6bdda85b5fd027a5056d8cd1345c1db3

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

end of thread, other threads:[~2024-05-02  3:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-30 11:41 [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 1/8] spi: armada-3700: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 2/8] spi: fsl-lpspi: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 3/8] spi: imx: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 4/8] spi: pic32-sqi: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 5/8] spi: pic32: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 6/8] spi: sun4i: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 7/8] spi: sun6i: " Wolfram Sang
2024-04-30 11:41 ` [PATCH v2 8/8] spi: xlp: " Wolfram Sang
2024-05-02  3:57 ` [PATCH v2 0/8] spi: use 'time_left' instead of 'timeout' with wait_for_*() functions Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).