* [PATCH] iio: accel: sca3000_core: avoid potentially uninitialized variable
@ 2016-09-22 9:43 Arnd Bergmann
2016-09-22 17:39 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-09-22 9:43 UTC (permalink / raw)
To: Jonathan Cameron, Greg Kroah-Hartman
Cc: Arnd Bergmann, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Ioana Ciornei, Ico Doornekamp, linux-iio,
devel, linux-kernel
The newly added __sca3000_get_base_freq function handles all valid
modes of the SCA3000_REG_ADDR_MODE register, but gcc notices
that any other value (i.e. 0x00) causes the base_freq variable to
not get initialized:
drivers/staging/iio/accel/sca3000_core.c: In function 'sca3000_write_raw':
drivers/staging/iio/accel/sca3000_core.c:527:23: error: 'base_freq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This adds explicit error handling for unexpected register values,
to ensure this cannot happen.
Fixes: e0f3fc9b47e6 ("iio: accel: sca3000_core: implemented IIO_CHAN_INFO_SAMP_FREQ")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/staging/iio/accel/sca3000_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index d626125d7af9..564b36d4f648 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -468,6 +468,8 @@ static inline int __sca3000_get_base_freq(struct sca3000_state *st,
case SCA3000_MEAS_MODE_OP_2:
*base_freq = info->option_mode_2_freq;
break;
+ default:
+ ret = -EINVAL;
}
error_ret:
return ret;
--
2.9.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: accel: sca3000_core: avoid potentially uninitialized variable
2016-09-22 9:43 [PATCH] iio: accel: sca3000_core: avoid potentially uninitialized variable Arnd Bergmann
@ 2016-09-22 17:39 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2016-09-22 17:39 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Ioana Ciornei, Ico Doornekamp, linux-iio, devel, linux-kernel
On 22/09/16 10:43, Arnd Bergmann wrote:
> The newly added __sca3000_get_base_freq function handles all valid
> modes of the SCA3000_REG_ADDR_MODE register, but gcc notices
> that any other value (i.e. 0x00) causes the base_freq variable to
> not get initialized:
>
> drivers/staging/iio/accel/sca3000_core.c: In function 'sca3000_write_raw':
> drivers/staging/iio/accel/sca3000_core.c:527:23: error: 'base_freq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> This adds explicit error handling for unexpected register values,
> to ensure this cannot happen.
>
> Fixes: e0f3fc9b47e6 ("iio: accel: sca3000_core: implemented IIO_CHAN_INFO_SAMP_FREQ")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied to the togreg branch of iio.git. Initially pushed out as testing for the
autobuilders to play with it.
'Bug' has been there a long time. The patch just move the code so I'm not
going to rush this one in. Worth hardening this corner though!
Thanks,
Jonathan
> ---
> drivers/staging/iio/accel/sca3000_core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
> index d626125d7af9..564b36d4f648 100644
> --- a/drivers/staging/iio/accel/sca3000_core.c
> +++ b/drivers/staging/iio/accel/sca3000_core.c
> @@ -468,6 +468,8 @@ static inline int __sca3000_get_base_freq(struct sca3000_state *st,
> case SCA3000_MEAS_MODE_OP_2:
> *base_freq = info->option_mode_2_freq;
> break;
> + default:
> + ret = -EINVAL;
> }
> error_ret:
> return ret;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-22 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 9:43 [PATCH] iio: accel: sca3000_core: avoid potentially uninitialized variable Arnd Bergmann
2016-09-22 17:39 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®