* [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
@ 2014-05-31 23:11 Rickard Strandqvist
2014-06-01 9:15 ` Lars-Peter Clausen
0 siblings, 1 reply; 5+ messages in thread
From: Rickard Strandqvist @ 2014-05-31 23:11 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen
Cc: Rickard Strandqvist, Andrew Morton, Linus Walleij, Wolfram Sang,
linux-iio, linux-kernel
There is a risk that the variable will be used without being initialized.
This was largely found by using a static code analysis program called cppcheck.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
drivers/iio/adc/ad_sigma_delta.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 9a4e0e3..d58fad9 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -248,7 +248,7 @@ 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, raw_sample = 0;
int ret = 0;
if (iio_buffer_enabled(indio_dev))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
2014-05-31 23:11 [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables Rickard Strandqvist
@ 2014-06-01 9:15 ` Lars-Peter Clausen
2014-06-01 11:51 ` Rickard Strandqvist
0 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2014-06-01 9:15 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Jonathan Cameron, Andrew Morton, Linus Walleij, Wolfram Sang,
linux-iio, linux-kernel
On 06/01/2014 01:11 AM, Rickard Strandqvist wrote:
> There is a risk that the variable will be used without being initialized.
>
> This was largely found by using a static code analysis program called cppcheck.
This looks like a false positive. And if it was not a false positive the
correct fix certainly is not to initialize the variable to some random value
to silence the warning.
- Lars
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
2014-06-01 9:15 ` Lars-Peter Clausen
@ 2014-06-01 11:51 ` Rickard Strandqvist
2014-06-01 12:03 ` Lars-Peter Clausen
0 siblings, 1 reply; 5+ messages in thread
From: Rickard Strandqvist @ 2014-06-01 11:51 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Jonathan Cameron, Andrew Morton, Linus Walleij, Wolfram Sang,
linux-iio, linux-kernel
Hi
Believe it reacted to the code below.
If raw_sample = 0 is the correct starting value, I am not sure. But
leaving it uninitialized, I think is the worst choice.
if (ret < 0)
goto out;
ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA,
DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8),
&raw_sample);
....
out:
....
sample = raw_sample >> chan->scan_type.shift;
Best regards
Rickard Strandqvist
2014-06-01 11:15 GMT+02:00 Lars-Peter Clausen <lars@metafoo.de>:
> On 06/01/2014 01:11 AM, Rickard Strandqvist wrote:
>>
>> There is a risk that the variable will be used without being initialized.
>>
>> This was largely found by using a static code analysis program called
>> cppcheck.
>
>
> This looks like a false positive. And if it was not a false positive the
> correct fix certainly is not to initialize the variable to some random value
> to silence the warning.
>
> - Lars
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
2014-06-01 11:51 ` Rickard Strandqvist
@ 2014-06-01 12:03 ` Lars-Peter Clausen
2014-06-01 12:10 ` Rickard Strandqvist
0 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2014-06-01 12:03 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Jonathan Cameron, Andrew Morton, Linus Walleij, Wolfram Sang,
linux-iio, linux-kernel
On 06/01/2014 01:51 PM, Rickard Strandqvist wrote:
> Hi
>
> Believe it reacted to the code below.
>
> If raw_sample = 0 is the correct starting value, I am not sure. But
> leaving it uninitialized, I think is the worst choice.
>
>
> if (ret < 0)
> goto out;
>
> ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA,
> DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8),
> &raw_sample);
> ....
> out:
> ....
you skipped the:
if (ret)
return ret;
that is here.
> sample = raw_sample >> chan->scan_type.shift;
>
The code is a bit confusing and it is understandable that a static checker
might generate a false positive. The fix though is not to silence the false
positive as this will hide actual problems if they should come up by future
modifications of the code.
>
> Best regards
> Rickard Strandqvist
>
>
> 2014-06-01 11:15 GMT+02:00 Lars-Peter Clausen <lars@metafoo.de>:
>> On 06/01/2014 01:11 AM, Rickard Strandqvist wrote:
>>>
>>> There is a risk that the variable will be used without being initialized.
>>>
>>> This was largely found by using a static code analysis program called
>>> cppcheck.
>>
>>
>> This looks like a false positive. And if it was not a false positive the
>> correct fix certainly is not to initialize the variable to some random value
>> to silence the warning.
>>
>> - Lars
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
2014-06-01 12:03 ` Lars-Peter Clausen
@ 2014-06-01 12:10 ` Rickard Strandqvist
0 siblings, 0 replies; 5+ messages in thread
From: Rickard Strandqvist @ 2014-06-01 12:10 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Jonathan Cameron, Andrew Morton, Linus Walleij, Wolfram Sang,
linux-iio, linux-kernel
Aaa, that is true! Sorry my mistake :(
Best regards
Rickard Strandqvist
2014-06-01 14:03 GMT+02:00 Lars-Peter Clausen <lars@metafoo.de>:
> On 06/01/2014 01:51 PM, Rickard Strandqvist wrote:
>>
>> Hi
>>
>> Believe it reacted to the code below.
>>
>> If raw_sample = 0 is the correct starting value, I am not sure. But
>> leaving it uninitialized, I think is the worst choice.
>>
>>
>> if (ret < 0)
>> goto out;
>>
>> ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA,
>> DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift,
>> 8),
>> &raw_sample);
>> ....
>> out:
>> ....
>
>
> you skipped the:
>
> if (ret)
> return ret;
>
> that is here.
>
>
>> sample = raw_sample >> chan->scan_type.shift;
>>
>
> The code is a bit confusing and it is understandable that a static checker
> might generate a false positive. The fix though is not to silence the false
> positive as this will hide actual problems if they should come up by future
> modifications of the code.
>
>
>>
>> Best regards
>> Rickard Strandqvist
>>
>>
>> 2014-06-01 11:15 GMT+02:00 Lars-Peter Clausen <lars@metafoo.de>:
>>>
>>> On 06/01/2014 01:11 AM, Rickard Strandqvist wrote:
>>>>
>>>>
>>>> There is a risk that the variable will be used without being
>>>> initialized.
>>>>
>>>> This was largely found by using a static code analysis program called
>>>> cppcheck.
>>>
>>>
>>>
>>> This looks like a false positive. And if it was not a false positive the
>>> correct fix certainly is not to initialize the variable to some random
>>> value
>>> to silence the warning.
>>>
>>> - Lars
>>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-01 12:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-31 23:11 [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables Rickard Strandqvist
2014-06-01 9:15 ` Lars-Peter Clausen
2014-06-01 11:51 ` Rickard Strandqvist
2014-06-01 12:03 ` Lars-Peter Clausen
2014-06-01 12:10 ` Rickard Strandqvist
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).