Skip to contentSkip to conversation

iio: adc: fix uninitialized variable warning

PATCH In review Arnd Bergmann 2 participants 2 messages Mar 4, 2019 – Mar 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: fix uninitialized variable warning

The pm8xxx_xoadc_probe() function triggers a bogus warning about an uninitialized variable:

drivers/iio/adc/qcom-pm8xxx-xoadc.c: In function 'pm8xxx_xoadc_probe':
drivers/iio/adc/qcom-pm8xxx-xoadc.c:633:8: error: 'ch' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Reword the function so the compiler can see more easily that it is always initialized.

Fixes 63c3ecd946d4 ("iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC")
---
 drivers/iio/adc/qcom-pm8xxx-xoadc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/qcom-pm8xxx-xoadc.c +1 -3
index c30c002f1fef..7939238001c8 100644
@@ -423,7 +423,7 @@ static irqreturn_t pm8xxx_eoc_irq(int irq, void *d)
 static struct pm8xxx_chan_info *
 pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan)
 {
-	struct pm8xxx_chan_info *ch;
+	struct pm8xxx_chan_info *ch = NULL;
 	int i;
 
 	for (i = 0; i < adc->nchans; i++) {
@@ -431,8 +431,6 @@ pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan)
 		if (ch->hwchan->amux_channel == chan)
 			break;
 	}
-	if (i == adc->nchans)
-		return NULL;
 
 	return ch;
 }
Signature · 1 line
2.20.0
maintainer
#1 lore raw
Quoted 11 lines · On Mon, 4 Mar 2019 21:03:07 +0100 Arnd Bergmann <[email protected]> wrote:

The pm8xxx_xoadc_probe() function triggers a bogus warning about an uninitialized variable:

drivers/iio/adc/qcom-pm8xxx-xoadc.c: In function 'pm8xxx_xoadc_probe':
drivers/iio/adc/qcom-pm8xxx-xoadc.c:633:8: error: 'ch' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Reword the function so the compiler can see more easily that it is always initialized.

Fixes 63c3ecd946d4 ("iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC")

Thanks.

For anyone seeing this here, Linus also picked up on it and applied a similar fix, so no need for this one.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/iio?id=e0f0ae838a25464179d37f355d763f9ec139fc15

Thanks,

Jonathan

Quoted 26 lines
---
 drivers/iio/adc/qcom-pm8xxx-xoadc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/qcom-pm8xxx-xoadc.c +1 -3
index c30c002f1fef..7939238001c8 100644
@@ -423,7 +423,7 @@ static irqreturn_t pm8xxx_eoc_irq(int irq, void *d)
 static struct pm8xxx_chan_info *
 pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan)
 {
-	struct pm8xxx_chan_info *ch;
+	struct pm8xxx_chan_info *ch = NULL;
 	int i;
 
 	for (i = 0; i < adc->nchans; i++) {
@@ -431,8 +431,6 @@ pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan)
 		if (ch->hwchan->amux_channel == chan)
 			break;
 	}
-	if (i == adc->nchans)
-		return NULL;
 
 	return ch;
 }