Skip to contentSkip to conversation

iio: adc: Call uninitialized_var for raw_sample

PATCH In review Darshana Padmadas 3 participants 3 messages Mar 19, 2015 – Mar 21, 2015

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

PATCH 1/1 iio: adc: Call uninitialized_var for raw_sample

This patch calls uninitialized_var function for uninitialized variable raw_sample. This error was reported by the static analysis tool, cppcheck.

---
 drivers/iio/adc/ad_sigma_delta.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ad_sigma_delta.c +2 -1
index d10bd0c..f0bbf3c 100644
@@ -248,7 +248,8 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	const struct iio_chan_spec *chan, int *val)
 {
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
-	unsigned int sample, raw_sample;
+	unsigned int sample;
+	unsigned int uninitialized_var(raw_sample);
 	int ret = 0;
 
 	if (iio_buffer_enabled(indio_dev))
Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Darshana Padmadas

This patch calls uninitialized_var function for uninitialized variable raw_sample. This error was reported by the static analysis tool, cppcheck.

---
 drivers/iio/adc/ad_sigma_delta.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ad_sigma_delta.c +0 -0
index d10bd0c..f0bbf3c 100644

drivers/iio/adc/ad_sigma_delta.c int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, · line 252

Quoted 6 lines
drivers/iio/adc/ad_sigma_delta.c +2 -1
@@ -248,7 +248,8 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	const struct iio_chan_spec *chan, int *val)
 {
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
-	unsigned int sample, raw_sample;
+	unsigned int sample;
+	unsigned int uninitialized_var(raw_sample);

I don't understand, what exactly is this "fixing"?

And note, cppcheck is known to give you lots of false warnings / errors, be very careful when using it. Some kernel developers refuse to take patches that mention it given that it has been wrong so many times in the past.

thanks,

greg k-h

maintainer
#2 lore raw
Quoted 24 lines · Greg KH
Quoted 14 lines · Darshana Padmadas

This patch calls uninitialized_var function for uninitialized variable raw_sample. This error was reported by the static analysis tool, cppcheck.

---
 drivers/iio/adc/ad_sigma_delta.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ad_sigma_delta.c +0 -0
index d10bd0c..f0bbf3c 100644

drivers/iio/adc/ad_sigma_delta.c int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, · line 252

Quoted 6 lines
drivers/iio/adc/ad_sigma_delta.c +2 -1
@@ -248,7 +248,8 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	const struct iio_chan_spec *chan, int *val)
 {
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
-	unsigned int sample, raw_sample;
+	unsigned int sample;
+	unsigned int uninitialized_var(raw_sample);

I don't understand, what exactly is this "fixing"?

Quoted 9 lines

And note, cppcheck is known to give you lots of false warnings / errors, be very careful when using it. Some kernel developers refuse to take patches that mention it given that it has been wrong so many times in the past.

thanks,

greg k-h

To clarify, the only way that variable can be used uninitialized is if we get an error from the spi transfer. If that happens we have an error code returned and hence don't use it anyway.

I suspect ccpcheck is either getting lost chasing through where that variable is used, or is falling for the fact that the value of ret is not checked for quite a few lines (so as to do some common cleanup which doesn't care if that function succeeded or not).

Anyhow, Greg is of course correct. False positive as far as I can see.

Jonathan