Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions
@ 2024-04-29 11:33 Wolfram Sang
  2024-04-29 11:33 ` [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout() Wolfram Sang
  2024-04-29 20:06 ` [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: Wolfram Sang @ 2024-04-29 11:33 UTC (permalink / raw)
  To: linux-iio
  Cc: Wolfram Sang, imx, linux-arm-kernel, linux-kernel,
	linux-samsung-soc, linux-stm32

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.

Wolfram Sang (8):
  iio: adc: ad_sigma_delta: use 'time_left' variable with
    wait_for_completion_timeout()
  iio: adc: exynos_adc: use 'time_left' variable with
    wait_for_completion_timeout()
  iio: adc: fsl-imx25-gcq: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()
  iio: adc: intel_mrfld_adc: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()
  iio: adc: stm32-adc: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()
  iio: adc: stm32-dfsdm-adc: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()
  iio: adc: twl6030-gpadc: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()
  iio: pressure: zpa2326: use 'time_left' variable with
    wait_for_completion_interruptible_timeout()

 drivers/iio/adc/ad_sigma_delta.c  |  6 +++---
 drivers/iio/adc/exynos_adc.c      | 16 ++++++++--------
 drivers/iio/adc/fsl-imx25-gcq.c   | 10 +++++-----
 drivers/iio/adc/intel_mrfld_adc.c | 12 ++++++------
 drivers/iio/adc/stm32-adc.c       | 10 +++++-----
 drivers/iio/adc/stm32-dfsdm-adc.c | 12 ++++++------
 drivers/iio/adc/twl6030-gpadc.c   |  8 ++++----
 drivers/iio/pressure/zpa2326.c    | 10 +++++-----
 8 files changed, 42 insertions(+), 42 deletions(-)

-- 
2.43.0


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

* [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout()
  2024-04-29 11:33 [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
  2024-04-30  1:36   ` Peng Fan
  2024-04-29 20:06 ` [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2024-04-29 11:33 UTC (permalink / raw)
  To: linux-iio
  Cc: Wolfram Sang, Jonathan Cameron, Lars-Peter Clausen, 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_interruptible_timeout() causing patterns like:

	timeout = wait_for_completion_interruptible_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/iio/adc/fsl-imx25-gcq.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 68c813de0605..dabc5303d644 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -107,7 +107,7 @@ static int mx25_gcq_get_raw_value(struct device *dev,
 				  struct mx25_gcq_priv *priv,
 				  int *val)
 {
-	long timeout;
+	long time_left;
 	u32 data;
 
 	/* Setup the configuration we want to use */
@@ -120,12 +120,12 @@ static int mx25_gcq_get_raw_value(struct device *dev,
 	regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS,
 			   MX25_ADCQ_CR_FQS);
 
-	timeout = wait_for_completion_interruptible_timeout(
+	time_left = wait_for_completion_interruptible_timeout(
 		&priv->completed, MX25_GCQ_TIMEOUT);
-	if (timeout < 0) {
+	if (time_left < 0) {
 		dev_err(dev, "ADC wait for measurement failed\n");
-		return timeout;
-	} else if (timeout == 0) {
+		return time_left;
+	} else if (time_left == 0) {
 		dev_err(dev, "ADC timed out\n");
 		return -ETIMEDOUT;
 	}
-- 
2.43.0


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

* Re: [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions
  2024-04-29 11:33 [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
  2024-04-29 11:33 ` [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout() Wolfram Sang
@ 2024-04-29 20:06 ` Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2024-04-29 20:06 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-iio, imx, linux-arm-kernel, linux-kernel, linux-samsung-soc,
	linux-stm32

On Mon, 29 Apr 2024 13:33:03 +0200
Wolfram Sang <wsa+renesas@sang-engineering.com> 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.
> 
> 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.

Nice improvement.  Applied

> 
> Wolfram Sang (8):
>   iio: adc: ad_sigma_delta: use 'time_left' variable with
>     wait_for_completion_timeout()
>   iio: adc: exynos_adc: use 'time_left' variable with
>     wait_for_completion_timeout()
>   iio: adc: fsl-imx25-gcq: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
>   iio: adc: intel_mrfld_adc: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
>   iio: adc: stm32-adc: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
>   iio: adc: stm32-dfsdm-adc: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
>   iio: adc: twl6030-gpadc: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
>   iio: pressure: zpa2326: use 'time_left' variable with
>     wait_for_completion_interruptible_timeout()
> 
>  drivers/iio/adc/ad_sigma_delta.c  |  6 +++---
>  drivers/iio/adc/exynos_adc.c      | 16 ++++++++--------
>  drivers/iio/adc/fsl-imx25-gcq.c   | 10 +++++-----
>  drivers/iio/adc/intel_mrfld_adc.c | 12 ++++++------
>  drivers/iio/adc/stm32-adc.c       | 10 +++++-----
>  drivers/iio/adc/stm32-dfsdm-adc.c | 12 ++++++------
>  drivers/iio/adc/twl6030-gpadc.c   |  8 ++++----
>  drivers/iio/pressure/zpa2326.c    | 10 +++++-----
>  8 files changed, 42 insertions(+), 42 deletions(-)
> 


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

* RE: [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout()
  2024-04-29 11:33 ` [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout() Wolfram Sang
@ 2024-04-30  1:36   ` Peng Fan
  0 siblings, 0 replies; 4+ messages in thread
From: Peng Fan @ 2024-04-30  1:36 UTC (permalink / raw)
  To: Wolfram Sang, linux-iio@vger.kernel.org
  Cc: Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org

> Subject: [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with
> wait_for_completion_interruptible_timeout()
> 
> There is a confusing pattern in the kernel to use a variable named 'timeout' to
> store the result of wait_for_completion_interruptible_timeout() causing
> patterns like:
> 
> 	timeout = wait_for_completion_interruptible_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/iio/adc/fsl-imx25-gcq.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
> index 68c813de0605..dabc5303d644 100644
> --- a/drivers/iio/adc/fsl-imx25-gcq.c
> +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> @@ -107,7 +107,7 @@ static int mx25_gcq_get_raw_value(struct device
> *dev,
>  				  struct mx25_gcq_priv *priv,
>  				  int *val)
>  {
> -	long timeout;
> +	long time_left;
>  	u32 data;
> 
>  	/* Setup the configuration we want to use */ @@ -120,12 +120,12
> @@ static int mx25_gcq_get_raw_value(struct device *dev,
>  	regmap_update_bits(priv->regs, MX25_ADCQ_CR,
> MX25_ADCQ_CR_FQS,
>  			   MX25_ADCQ_CR_FQS);
> 
> -	timeout = wait_for_completion_interruptible_timeout(
> +	time_left = wait_for_completion_interruptible_timeout(
>  		&priv->completed, MX25_GCQ_TIMEOUT);
> -	if (timeout < 0) {
> +	if (time_left < 0) {
>  		dev_err(dev, "ADC wait for measurement failed\n");
> -		return timeout;
> -	} else if (timeout == 0) {
> +		return time_left;
> +	} else if (time_left == 0) {
>  		dev_err(dev, "ADC timed out\n");
>  		return -ETIMEDOUT;
>  	}
> --
> 2.43.0
> 


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

end of thread, other threads:[~2024-04-30  1:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-29 11:33 [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Wolfram Sang
2024-04-29 11:33 ` [PATCH 3/8] iio: adc: fsl-imx25-gcq: use 'time_left' variable with wait_for_completion_interruptible_timeout() Wolfram Sang
2024-04-30  1:36   ` Peng Fan
2024-04-29 20:06 ` [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Jonathan Cameron

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