linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: fix uninitialized variable warning
@ 2019-03-04 20:03 Arnd Bergmann
  2019-03-09 18:10 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2019-03-04 20:03 UTC (permalink / raw)
  To: Andy Gross, David Brown, Jonathan Cameron
  Cc: Arnd Bergmann, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-arm-msm, linux-iio, linux-kernel

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/iio/adc/qcom-pm8xxx-xoadc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
index c30c002f1fef..7939238001c8 100644
--- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c
+++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
@@ -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;
 }
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: adc: fix uninitialized variable warning
  2019-03-04 20:03 [PATCH] iio: adc: fix uninitialized variable warning Arnd Bergmann
@ 2019-03-09 18:10 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-03-09 18:10 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andy Gross, David Brown, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-arm-msm, linux-iio, linux-kernel

On Mon,  4 Mar 2019 21:03:07 +0100
Arnd Bergmann <arnd@arndb.de> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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

> ---
>  drivers/iio/adc/qcom-pm8xxx-xoadc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
> index c30c002f1fef..7939238001c8 100644
> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c
> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
> @@ -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;
>  }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-09 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-04 20:03 [PATCH] iio: adc: fix uninitialized variable warning Arnd Bergmann
2019-03-09 18:10 ` 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).