2024-04-29 11:42:06

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions

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



2024-04-29 11:42:20

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout()

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 <[email protected]>
---
drivers/iio/adc/ad_sigma_delta.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index a602429cdde4..40ba6506bfc1 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -206,7 +206,7 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
unsigned int mode, unsigned int channel)
{
int ret;
- unsigned long timeout;
+ unsigned long time_left;

ret = ad_sigma_delta_set_channel(sigma_delta, channel);
if (ret)
@@ -223,8 +223,8 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,

sigma_delta->irq_dis = false;
enable_irq(sigma_delta->spi->irq);
- timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
- if (timeout == 0) {
+ time_left = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
+ if (time_left == 0) {
sigma_delta->irq_dis = true;
disable_irq_nosync(sigma_delta->spi->irq);
ret = -EIO;
--
2.43.0


2024-04-29 11:44:46

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 2/8] iio: adc: exynos_adc: use 'time_left' variable with wait_for_completion_timeout()

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 <[email protected]>
---
drivers/iio/adc/exynos_adc.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 614de9644800..78fada4b7b1c 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -538,7 +538,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
long mask)
{
struct exynos_adc *info = iio_priv(indio_dev);
- unsigned long timeout;
+ unsigned long time_left;
int ret;

if (mask == IIO_CHAN_INFO_SCALE) {
@@ -562,9 +562,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
if (info->data->start_conv)
info->data->start_conv(info, chan->address);

- timeout = wait_for_completion_timeout(&info->completion,
- EXYNOS_ADC_TIMEOUT);
- if (timeout == 0) {
+ time_left = wait_for_completion_timeout(&info->completion,
+ EXYNOS_ADC_TIMEOUT);
+ if (time_left == 0) {
dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
if (info->data->init_hw)
info->data->init_hw(info);
@@ -583,7 +583,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
{
struct exynos_adc *info = iio_priv(indio_dev);
- unsigned long timeout;
+ unsigned long time_left;
int ret;

mutex_lock(&info->lock);
@@ -597,9 +597,9 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
/* Select the ts channel to be used and Trigger conversion */
info->data->start_conv(info, ADC_S3C2410_MUX_TS);

- timeout = wait_for_completion_timeout(&info->completion,
- EXYNOS_ADC_TIMEOUT);
- if (timeout == 0) {
+ time_left = wait_for_completion_timeout(&info->completion,
+ EXYNOS_ADC_TIMEOUT);
+ if (time_left == 0) {
dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
if (info->data->init_hw)
info->data->init_hw(info);
--
2.43.0


2024-04-29 11:46:37

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 4/8] iio: adc: intel_mrfld_adc: 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 <[email protected]>
---
drivers/iio/adc/intel_mrfld_adc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/intel_mrfld_adc.c b/drivers/iio/adc/intel_mrfld_adc.c
index 7263ad76124d..c7f40ae6e608 100644
--- a/drivers/iio/adc/intel_mrfld_adc.c
+++ b/drivers/iio/adc/intel_mrfld_adc.c
@@ -75,7 +75,7 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
struct mrfld_adc *adc = iio_priv(indio_dev);
struct regmap *regmap = adc->regmap;
unsigned int req;
- long timeout;
+ long time_left;
__be16 value;
int ret;

@@ -95,13 +95,13 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
if (ret)
goto done;

- timeout = wait_for_completion_interruptible_timeout(&adc->completion,
- BCOVE_ADC_TIMEOUT);
- if (timeout < 0) {
- ret = timeout;
+ time_left = wait_for_completion_interruptible_timeout(&adc->completion,
+ BCOVE_ADC_TIMEOUT);
+ if (time_left < 0) {
+ ret = time_left;
goto done;
}
- if (timeout == 0) {
+ if (time_left == 0) {
ret = -ETIMEDOUT;
goto done;
}
--
2.43.0


2024-04-29 12:02:37

by Nuno Sá

[permalink] [raw]
Subject: Re: [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout()

On Mon, 2024-04-29 at 13:33 +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_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 <[email protected]>
> ---

Reviewed-by: Nuno Sa <[email protected]>

>  drivers/iio/adc/ad_sigma_delta.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c
> b/drivers/iio/adc/ad_sigma_delta.c
> index a602429cdde4..40ba6506bfc1 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -206,7 +206,7 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
>   unsigned int mode, unsigned int channel)
>  {
>   int ret;
> - unsigned long timeout;
> + unsigned long time_left;
>  
>   ret = ad_sigma_delta_set_channel(sigma_delta, channel);
>   if (ret)
> @@ -223,8 +223,8 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
>  
>   sigma_delta->irq_dis = false;
>   enable_irq(sigma_delta->spi->irq);
> - timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 *
> HZ);
> - if (timeout == 0) {
> + time_left = wait_for_completion_timeout(&sigma_delta->completion, 2 *
> HZ);
> + if (time_left == 0) {
>   sigma_delta->irq_dis = true;
>   disable_irq_nosync(sigma_delta->spi->irq);
>   ret = -EIO;


2024-04-29 20:07:39

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions

On Mon, 29 Apr 2024 13:33:03 +0200
Wolfram Sang <[email protected]> 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(-)
>