From: Lars-Peter Clausen <lars@metafoo.de>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Jonathan Cameron <jic23@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Walleij <linus.walleij@linaro.org>,
Wolfram Sang <wsa@the-dreams.de>,
linux-iio@vger.kernel.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: ad_sigma_delta.c: Cleaning up uninitialized variables
Date: Sun, 01 Jun 2014 14:03:10 +0200 [thread overview]
Message-ID: <538B167E.9030902@metafoo.de> (raw)
In-Reply-To: <CAFo99gaTK__WX4oTr_jF6PZuTOsX8qbR9kRJbgamZPO4iGz53w@mail.gmail.com>
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
>>
next prev parent reply other threads:[~2014-06-01 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2014-06-01 12:10 ` Rickard Strandqvist
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=538B167E.9030902@metafoo.de \
--to=lars@metafoo.de \
--cc=akpm@linux-foundation.org \
--cc=jic23@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.