* [PATCH] iio: adc: Fix incorrect exit of for-loop
@ 2021-07-30 7:16 Colin King
2021-07-31 13:47 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-07-30 7:16 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Lee Jones, Laxman Dewangan,
Pradeep Goudagunta, Marek Belisko, linux-iio
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the for-loop that scans for the optimial adc_period iterates
through all the possible adc_period levels because the exit logic in
the loop is inverted. I believe the comparison should be swapped and
the continue replaced with a break to exit the loop at the correct
point.
Addresses-Coverity: ("Continue has no effect")
Fixes: e08e19c331fb ("iio:adc: add iio driver for Palmas (twl6035/7) gpadc")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/iio/adc/palmas_gpadc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
index 6ef09609be9f..f9c8385c72d3 100644
--- a/drivers/iio/adc/palmas_gpadc.c
+++ b/drivers/iio/adc/palmas_gpadc.c
@@ -664,8 +664,8 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
adc_period = adc->auto_conversion_period;
for (i = 0; i < 16; ++i) {
- if (((1000 * (1 << i)) / 32) < adc_period)
- continue;
+ if (((1000 * (1 << i)) / 32) >= adc_period)
+ break;
}
if (i > 0)
i--;
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: adc: Fix incorrect exit of for-loop
2021-07-30 7:16 [PATCH] iio: adc: Fix incorrect exit of for-loop Colin King
@ 2021-07-31 13:47 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-07-31 13:47 UTC (permalink / raw)
To: Colin King
Cc: Lars-Peter Clausen, Lee Jones, Laxman Dewangan,
Pradeep Goudagunta, Marek Belisko, linux-iio, kernel-janitors,
linux-kernel
On Fri, 30 Jul 2021 08:16:51 +0100
Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the for-loop that scans for the optimial adc_period iterates
> through all the possible adc_period levels because the exit logic in
> the loop is inverted. I believe the comparison should be swapped and
> the continue replaced with a break to exit the loop at the correct
> point.
>
> Addresses-Coverity: ("Continue has no effect")
> Fixes: e08e19c331fb ("iio:adc: add iio driver for Palmas (twl6035/7) gpadc")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
ouch.
Applied to the fixes togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
> ---
> drivers/iio/adc/palmas_gpadc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
> index 6ef09609be9f..f9c8385c72d3 100644
> --- a/drivers/iio/adc/palmas_gpadc.c
> +++ b/drivers/iio/adc/palmas_gpadc.c
> @@ -664,8 +664,8 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
>
> adc_period = adc->auto_conversion_period;
> for (i = 0; i < 16; ++i) {
> - if (((1000 * (1 << i)) / 32) < adc_period)
> - continue;
> + if (((1000 * (1 << i)) / 32) >= adc_period)
> + break;
> }
> if (i > 0)
> i--;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-31 13:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 7:16 [PATCH] iio: adc: Fix incorrect exit of for-loop Colin King
2021-07-31 13:47 ` 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 NNTP newsgroup(s).