* [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 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
` (8 more replies)
0 siblings, 9 replies; 12+ 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] 12+ messages in thread
* [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_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-29 12:06 ` Nuno Sá
2024-04-29 11:33 ` [PATCH 2/8] iio: adc: exynos_adc: " Wolfram Sang
` (7 subsequent siblings)
8 siblings, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2024-04-29 11:33 UTC (permalink / raw
To: linux-iio
Cc: Wolfram Sang, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, 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/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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/8] iio: adc: exynos_adc: use 'time_left' variable with wait_for_completion_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 ` [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 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
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ 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,
Krzysztof Kozlowski, Alim Akhtar, linux-arm-kernel,
linux-samsung-soc, 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/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
^ permalink raw reply related [flat|nested] 12+ 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 ` [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-04-29 11:33 ` [PATCH 2/8] iio: adc: exynos_adc: " Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
2024-04-30 1:36 ` Peng Fan
2024-04-29 11:33 ` [PATCH 4/8] iio: adc: intel_mrfld_adc: " Wolfram Sang
` (5 subsequent siblings)
8 siblings, 1 reply; 12+ 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] 12+ messages in thread
* [PATCH 4/8] iio: adc: intel_mrfld_adc: 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
` (2 preceding siblings ...)
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 11:33 ` Wolfram Sang
2024-04-29 11:33 ` [PATCH 5/8] iio: adc: stm32-adc: " Wolfram Sang
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ 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, 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/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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/8] iio: adc: stm32-adc: 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
` (3 preceding siblings ...)
2024-04-29 11:33 ` [PATCH 4/8] iio: adc: intel_mrfld_adc: " Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
2024-04-29 11:33 ` [PATCH 6/8] iio: adc: stm32-dfsdm-adc: " Wolfram Sang
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ 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,
Maxime Coquelin, Alexandre Torgue, linux-stm32, 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/stm32-adc.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index b5d3c9cea5c4..7cad0ce1d9b9 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1408,7 +1408,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev,
struct stm32_adc *adc = iio_priv(indio_dev);
struct device *dev = indio_dev->dev.parent;
const struct stm32_adc_regspec *regs = adc->cfg->regs;
- long timeout;
+ long time_left;
u32 val;
int ret;
@@ -1440,12 +1440,12 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev,
adc->cfg->start_conv(indio_dev, false);
- timeout = wait_for_completion_interruptible_timeout(
+ time_left = wait_for_completion_interruptible_timeout(
&adc->completion, STM32_ADC_TIMEOUT);
- if (timeout == 0) {
+ if (time_left == 0) {
ret = -ETIMEDOUT;
- } else if (timeout < 0) {
- ret = timeout;
+ } else if (time_left < 0) {
+ ret = time_left;
} else {
*res = adc->buffer[0];
ret = IIO_VAL_INT;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/8] iio: adc: stm32-dfsdm-adc: 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
` (4 preceding siblings ...)
2024-04-29 11:33 ` [PATCH 5/8] iio: adc: stm32-adc: " Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
2024-04-29 11:33 ` [PATCH 7/8] iio: adc: twl6030-gpadc: " Wolfram Sang
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ 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,
Maxime Coquelin, Alexandre Torgue, linux-stm32, 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/stm32-dfsdm-adc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
index ca08ae3108b2..9a47d2c87f05 100644
--- a/drivers/iio/adc/stm32-dfsdm-adc.c
+++ b/drivers/iio/adc/stm32-dfsdm-adc.c
@@ -1116,7 +1116,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *res)
{
struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
- long timeout;
+ long time_left;
int ret;
reinit_completion(&adc->completion);
@@ -1141,17 +1141,17 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev,
goto stop_dfsdm;
}
- timeout = wait_for_completion_interruptible_timeout(&adc->completion,
- DFSDM_TIMEOUT);
+ time_left = wait_for_completion_interruptible_timeout(&adc->completion,
+ DFSDM_TIMEOUT);
/* Mask IRQ for regular conversion achievement*/
regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));
- if (timeout == 0)
+ if (time_left == 0)
ret = -ETIMEDOUT;
- else if (timeout < 0)
- ret = timeout;
+ else if (time_left < 0)
+ ret = time_left;
else
ret = IIO_VAL_INT;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 7/8] iio: adc: twl6030-gpadc: 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
` (5 preceding siblings ...)
2024-04-29 11:33 ` [PATCH 6/8] iio: adc: stm32-dfsdm-adc: " Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
2024-04-29 11:33 ` [PATCH 8/8] iio: pressure: zpa2326: " Wolfram Sang
2024-04-29 20:06 ` [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Jonathan Cameron
8 siblings, 0 replies; 12+ 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, 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/twl6030-gpadc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index 78bf55438b2c..6a3db2bce460 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -519,7 +519,7 @@ static int twl6030_gpadc_read_raw(struct iio_dev *indio_dev,
{
struct twl6030_gpadc_data *gpadc = iio_priv(indio_dev);
int ret;
- long timeout;
+ long time_left;
mutex_lock(&gpadc->lock);
@@ -529,12 +529,12 @@ static int twl6030_gpadc_read_raw(struct iio_dev *indio_dev,
goto err;
}
/* wait for conversion to complete */
- timeout = wait_for_completion_interruptible_timeout(
+ time_left = wait_for_completion_interruptible_timeout(
&gpadc->irq_complete, msecs_to_jiffies(5000));
- if (timeout == 0) {
+ if (time_left == 0) {
ret = -ETIMEDOUT;
goto err;
- } else if (timeout < 0) {
+ } else if (time_left < 0) {
ret = -EINTR;
goto err;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 8/8] iio: pressure: zpa2326: 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
` (6 preceding siblings ...)
2024-04-29 11:33 ` [PATCH 7/8] iio: adc: twl6030-gpadc: " Wolfram Sang
@ 2024-04-29 11:33 ` Wolfram Sang
2024-04-29 20:06 ` [PATCH 0/8] iio: use 'time_left' instead of 'timeout' with wait_for_*() functions Jonathan Cameron
8 siblings, 0 replies; 12+ 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, 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/pressure/zpa2326.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index 421e059d1f19..dcc87a9015e8 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -861,13 +861,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev *indio_dev,
struct zpa2326_private *private)
{
unsigned int val;
- long timeout;
+ long time_left;
zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
- timeout = wait_for_completion_interruptible_timeout(
+ time_left = wait_for_completion_interruptible_timeout(
&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
- if (timeout > 0)
+ if (time_left > 0)
/*
* Interrupt handler completed before timeout: return operation
* status.
@@ -877,10 +877,10 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev *indio_dev,
/* Clear all interrupts just to be sure. */
regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
- if (!timeout) {
+ if (!time_left) {
/* Timed out. */
zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
- timeout);
+ time_left);
return -ETIME;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout()
2024-04-29 11:33 ` [PATCH 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 2024-04-29 12:06 ` Nuno Sá
0 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2024-04-29 12:06 UTC (permalink / raw
To: Wolfram Sang, linux-iio
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
linux-kernel
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 <wsa+renesas@sang-engineering.com>
> ---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 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;
^ permalink raw reply [flat|nested] 12+ 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
` (7 preceding siblings ...)
2024-04-29 11:33 ` [PATCH 8/8] iio: pressure: zpa2326: " Wolfram Sang
@ 2024-04-29 20:06 ` Jonathan Cameron
8 siblings, 0 replies; 12+ 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] 12+ 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; 12+ 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] 12+ messages in thread
end of thread, other threads:[~2024-04-30 1:36 UTC | newest]
Thread overview: 12+ 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 1/8] iio: adc: ad_sigma_delta: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-04-29 12:06 ` Nuno Sá
2024-04-29 11:33 ` [PATCH 2/8] iio: adc: exynos_adc: " 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 11:33 ` [PATCH 4/8] iio: adc: intel_mrfld_adc: " Wolfram Sang
2024-04-29 11:33 ` [PATCH 5/8] iio: adc: stm32-adc: " Wolfram Sang
2024-04-29 11:33 ` [PATCH 6/8] iio: adc: stm32-dfsdm-adc: " Wolfram Sang
2024-04-29 11:33 ` [PATCH 7/8] iio: adc: twl6030-gpadc: " Wolfram Sang
2024-04-29 11:33 ` [PATCH 8/8] iio: pressure: zpa2326: " Wolfram Sang
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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).