public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] adis16080: fix compiler -Wuninitialized
@ 2012-02-14 14:35 Danny Kukawka
  2012-02-14 15:04 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Danny Kukawka @ 2012-02-14 14:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Danny Kukawka, Michael Hennerich, Lars-Peter Clausen,
	Paul Gortmaker, linux-iio, devel, linux-kernel

Fix for:
drivers/staging/iio/gyro/adis16080_core.c: In function
  ‘adis16080_read_raw’:
drivers/staging/iio/gyro/adis16080_core.c:99:8: warning: ‘ut’
  may be used uninitialized in this function [-Wuninitialized]

Initialize ut and change error handling from adis16080_read_raw().

Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
---
 drivers/staging/iio/gyro/adis16080_core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c
index 1815490..e0b2a29 100644
--- a/drivers/staging/iio/gyro/adis16080_core.c
+++ b/drivers/staging/iio/gyro/adis16080_core.c
@@ -82,7 +82,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
 			     long mask)
 {
 	int ret = -EINVAL;
-	u16 ut;
+	u16 ut = 0;
 	/* Take the iio_dev status lock */
 
 	mutex_lock(&indio_dev->mlock);
@@ -94,7 +94,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
 		if (ret < 0)
 			break;
 		ret = adis16080_spi_read(indio_dev, &ut);
-		if (ret < 0)
+		if (ret)
 			break;
 		*val = ut;
 		ret = IIO_VAL_INT;
-- 
1.7.7.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] adis16080: fix compiler -Wuninitialized
  2012-02-14 14:35 [PATCH] adis16080: fix compiler -Wuninitialized Danny Kukawka
@ 2012-02-14 15:04 ` Dan Carpenter
  2012-02-14 15:18   ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-02-14 15:04 UTC (permalink / raw)
  To: Danny Kukawka
  Cc: Greg Kroah-Hartman, devel, Lars-Peter Clausen, Michael Hennerich,
	linux-iio, Danny Kukawka, linux-kernel, Paul Gortmaker

[-- Attachment #1: Type: text/plain, Size: 2012 bytes --]

On Tue, Feb 14, 2012 at 03:35:36PM +0100, Danny Kukawka wrote:
> Fix for:
> drivers/staging/iio/gyro/adis16080_core.c: In function
>   ‘adis16080_read_raw’:
> drivers/staging/iio/gyro/adis16080_core.c:99:8: warning: ‘ut’
>   may be used uninitialized in this function [-Wuninitialized]
> 
> Initialize ut and change error handling from adis16080_read_raw().
> 
> Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
> ---
>  drivers/staging/iio/gyro/adis16080_core.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c
> index 1815490..e0b2a29 100644
> --- a/drivers/staging/iio/gyro/adis16080_core.c
> +++ b/drivers/staging/iio/gyro/adis16080_core.c
> @@ -82,7 +82,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
>  			     long mask)
>  {
>  	int ret = -EINVAL;
> -	u16 ut;
> +	u16 ut = 0;
>  	/* Take the iio_dev status lock */
>  
>  	mutex_lock(&indio_dev->mlock);
> @@ -94,7 +94,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
>  		if (ret < 0)
>  			break;
>  		ret = adis16080_spi_read(indio_dev, &ut);
> -		if (ret < 0)
> +		if (ret)
>  			break;

Either one of these changes would silence the warning from gcc
(which is a false positive).  I would keep the "ut = 0;" change and
leave the error handling the same.  That way we check for less than
zero consistently instead of checking some for non-zero and some for
less than zero.

I normally wouldn't have commented on this if the changelog had said
whether it was a gcc false positive or if the code changes the
behavior.  It really should be mentioned.

If you could put a "Staging:" and an "iio" in the subject, that
would be grand as well.  Everyone seems to be using the prefix
"staging:iio:gyro:adis16080" for that file...  I don't know why they
don't just use slashes if they're going to specify the whole file...

regards,
dan carpenter

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] adis16080: fix compiler -Wuninitialized
  2012-02-14 15:04 ` Dan Carpenter
@ 2012-02-14 15:18   ` Jonathan Cameron
  2012-02-14 17:36     ` Danny Kukawka
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2012-02-14 15:18 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Danny Kukawka, Greg Kroah-Hartman, devel, Lars-Peter Clausen,
	Michael Hennerich, linux-iio, Danny Kukawka, linux-kernel,
	Paul Gortmaker

On 2/14/2012 3:04 PM, Dan Carpenter wrote:
> On Tue, Feb 14, 2012 at 03:35:36PM +0100, Danny Kukawka wrote:
>> Fix for:
>> drivers/staging/iio/gyro/adis16080_core.c: In function
>>    ‘adis16080_read_raw’:
>> drivers/staging/iio/gyro/adis16080_core.c:99:8: warning: ‘ut’
>>    may be used uninitialized in this function [-Wuninitialized]
>>
>> Initialize ut and change error handling from adis16080_read_raw().
>>
>> Signed-off-by: Danny Kukawka<danny.kukawka@bisect.de>
>> ---
>>   drivers/staging/iio/gyro/adis16080_core.c |    4 ++--
>>   1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c
>> index 1815490..e0b2a29 100644
>> --- a/drivers/staging/iio/gyro/adis16080_core.c
>> +++ b/drivers/staging/iio/gyro/adis16080_core.c
>> @@ -82,7 +82,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
>>   			     long mask)
>>   {
>>   	int ret = -EINVAL;
>> -	u16 ut;
>> +	u16 ut = 0;
>>   	/* Take the iio_dev status lock */
>>
>>   	mutex_lock(&indio_dev->mlock);
>> @@ -94,7 +94,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
>>   		if (ret<  0)
>>   			break;
>>   		ret = adis16080_spi_read(indio_dev,&ut);
>> -		if (ret<  0)
>> +		if (ret)
>>   			break;
> Either one of these changes would silence the warning from gcc
> (which is a false positive).  I would keep the "ut = 0;" change and
> leave the error handling the same.  That way we check for less than
> zero consistently instead of checking some for non-zero and some for
> less than zero.
Agreed.  I've always been lazy on this one as it was a false positive, 
but might as well
get rid of it...
>
> I normally wouldn't have commented on this if the changelog had said
> whether it was a gcc false positive or if the code changes the
> behavior.  It really should be mentioned.
>
> If you could put a "Staging:" and an "iio" in the subject, that
> would be grand as well.  Everyone seems to be using the prefix
> "staging:iio:gyro:adis16080" for that file...  I don't know why they
> don't just use slashes if they're going to specify the whole file...
Fair point.   Ah well, habits die hard.  Sometimes we have things like
staging:iio:treewide which is probably why I started doing this...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] adis16080: fix compiler -Wuninitialized
  2012-02-14 15:18   ` Jonathan Cameron
@ 2012-02-14 17:36     ` Danny Kukawka
  0 siblings, 0 replies; 4+ messages in thread
From: Danny Kukawka @ 2012-02-14 17:36 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Dan Carpenter, Greg Kroah-Hartman, devel, Lars-Peter Clausen,
	Michael Hennerich, linux-iio, linux-kernel, Paul Gortmaker

On Dienstag, 14. Februar 2012, Jonathan Cameron wrote:
> On 2/14/2012 3:04 PM, Dan Carpenter wrote:
> > On Tue, Feb 14, 2012 at 03:35:36PM +0100, Danny Kukawka wrote:
> >> Fix for:
> >> drivers/staging/iio/gyro/adis16080_core.c: In function
> >>    ‘adis16080_read_raw’:
> >> drivers/staging/iio/gyro/adis16080_core.c:99:8: warning: ‘ut’
> >>    may be used uninitialized in this function [-Wuninitialized]
> >>
> >> Initialize ut and change error handling from adis16080_read_raw().
> >>
> >> Signed-off-by: Danny Kukawka<danny.kukawka@bisect.de>
> >> ---
> >>   drivers/staging/iio/gyro/adis16080_core.c |    4 ++--
> >>   1 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/staging/iio/gyro/adis16080_core.c
> >> b/drivers/staging/iio/gyro/adis16080_core.c index 1815490..e0b2a29
> >> 100644
> >> --- a/drivers/staging/iio/gyro/adis16080_core.c
> >> +++ b/drivers/staging/iio/gyro/adis16080_core.c
> >> @@ -82,7 +82,7 @@ static int adis16080_read_raw(struct iio_dev
> >> *indio_dev, long mask)
> >>   {
> >>   	int ret = -EINVAL;
> >> -	u16 ut;
> >> +	u16 ut = 0;
> >>   	/* Take the iio_dev status lock */
> >>
> >>   	mutex_lock(&indio_dev->mlock);
> >> @@ -94,7 +94,7 @@ static int adis16080_read_raw(struct iio_dev
> >> *indio_dev, if (ret<  0)
> >>   			break;
> >>   		ret = adis16080_spi_read(indio_dev,&ut);
> >> -		if (ret<  0)
> >> +		if (ret)
> >>   			break;
> >
> > Either one of these changes would silence the warning from gcc
> > (which is a false positive).  I would keep the "ut = 0;" change and
> > leave the error handling the same.  That way we check for less than
> > zero consistently instead of checking some for non-zero and some for
> > less than zero.
>
> Agreed.  I've always been lazy on this one as it was a false positive,
> but might as well
> get rid of it...

I'm okay with 'ut = 0;'. 

I guess it's hard for gcc to find out that spi_read() will only return 0 or a 
negative value in error case. That's why gcc may assume 'ut' could be used 
initialized since adis16080_spi_read() may return with a value > 0.

And in case spi_read() or one of the functions behind would change it could 
cause an initialized 'ut'. The code may should always check for "ret != 0" as 
already done in some other places (in similar cases) to be save.

Danny

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-14 17:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-14 14:35 [PATCH] adis16080: fix compiler -Wuninitialized Danny Kukawka
2012-02-14 15:04 ` Dan Carpenter
2012-02-14 15:18   ` Jonathan Cameron
2012-02-14 17:36     ` Danny Kukawka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox