From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752073AbbCULte (ORCPT ); Sat, 21 Mar 2015 07:49:34 -0400 Received: from saturn.retrosnub.co.uk ([178.18.118.26]:59281 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752036AbbCULt3 (ORCPT ); Sat, 21 Mar 2015 07:49:29 -0400 Message-ID: <550D5AC7.6050105@kernel.org> Date: Sat, 21 Mar 2015 11:49:27 +0000 From: Jonathan Cameron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Greg KH , Darshana Padmadas CC: outreachy-kernel@googlegroups.com, linux-kernel@vger.kernel.org Subject: Re: [Outreachy kernel] [PATCH] iio: adc: Call uninitialized_var for raw_sample References: <1426772061-20753-1-git-send-email-darshanapadmadas@gmail.com> <20150319140511.GA7046@kroah.com> In-Reply-To: <20150319140511.GA7046@kroah.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/03/15 14:05, Greg KH wrote: > On Thu, Mar 19, 2015 at 07:04:21PM +0530, Darshana Padmadas wrote: >> This patch calls uninitialized_var function for uninitialized >> variable raw_sample. This error was reported by the static >> analysis tool, cppcheck. >> >> Signed-off-by: Darshana Padmadas >> --- >> drivers/iio/adc/ad_sigma_delta.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c >> index d10bd0c..f0bbf3c 100644 >> --- a/drivers/iio/adc/ad_sigma_delta.c >> +++ b/drivers/iio/adc/ad_sigma_delta.c >> @@ -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 > 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