Skip to contentSkip to conversation

iio: adc: Fix incorrect exit of for-loop

PATCH Applied Colin King 2 participants 2 messages Jul 30, 2021 – Jul 31, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 iio: adc: Fix incorrect exit of for-loop

From: Colin Ian King <[email protected]>

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")
---
 drivers/iio/adc/palmas_gpadc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/palmas_gpadc.c +2 -2
index 6ef09609be9f..f9c8385c72d3 100644
@@ -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--;
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 11 lines · On Fri, 30 Jul 2021 08:16:51 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

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")

ouch.

Applied to the fixes togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 19 lines
---
 drivers/iio/adc/palmas_gpadc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/palmas_gpadc.c +2 -2
index 6ef09609be9f..f9c8385c72d3 100644
@@ -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--;