linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: light: isl29501: Simplify code to kill compiler warning
@ 2018-08-23 21:24 Geert Uytterhoeven
  2018-08-25  8:30 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2018-08-23 21:24 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Mathieu Othacehe
  Cc: Arnd Bergmann, linux-iio, linux-kernel, Geert Uytterhoeven

With gcc 4.1.2:

    drivers/iio/proximity/isl29501.c: In function ‘isl29501_register_write’:
    drivers/iio/proximity/isl29501.c:235: warning: ‘msb’ may be used uninitialized in this function

While this is a false positive, it can easily be avoided by removing the
"msb" intermediate variable.
Remove the "lsb" intermediate variable for consistency.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Compile-tested only.
---
 drivers/iio/proximity/isl29501.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
index e5e94540f404dd2c..5ae549075b27c50d 100644
--- a/drivers/iio/proximity/isl29501.c
+++ b/drivers/iio/proximity/isl29501.c
@@ -232,7 +232,6 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
 				   u32 value)
 {
 	const struct isl29501_register_desc *reg = &isl29501_registers[name];
-	u8 msb, lsb;
 	int ret;
 
 	if (!reg->msb && value > U8_MAX)
@@ -241,22 +240,15 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
 	if (value > U16_MAX)
 		return -ERANGE;
 
-	if (!reg->msb) {
-		lsb = value & 0xFF;
-	} else {
-		msb = (value >> 8) & 0xFF;
-		lsb = value & 0xFF;
-	}
-
 	mutex_lock(&isl29501->lock);
 	if (reg->msb) {
 		ret = i2c_smbus_write_byte_data(isl29501->client,
-						reg->msb, msb);
+						reg->msb, value >> 8);
 		if (ret < 0)
 			goto err;
 	}
 
-	ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, lsb);
+	ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, value);
 
 err:
 	mutex_unlock(&isl29501->lock);
-- 
2.17.1

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

* Re: [PATCH] iio: light: isl29501: Simplify code to kill compiler warning
  2018-08-23 21:24 [PATCH] iio: light: isl29501: Simplify code to kill compiler warning Geert Uytterhoeven
@ 2018-08-25  8:30 ` Jonathan Cameron
  2018-09-02  8:59   ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2018-08-25  8:30 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Mathieu Othacehe, Arnd Bergmann, linux-iio, linux-kernel

On Thu, 23 Aug 2018 23:24:35 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> With gcc 4.1.2:
>=20
>     drivers/iio/proximity/isl29501.c: In function =E2=80=98isl29501_regis=
ter_write=E2=80=99:
>     drivers/iio/proximity/isl29501.c:235: warning: =E2=80=98msb=E2=80=99 =
may be used uninitialized in this function
>=20
> While this is a false positive, it can easily be avoided by removing the
> "msb" intermediate variable.
> Remove the "lsb" intermediate variable for consistency.
>=20
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Looks sensible to me, but I'd obviously like to leave a little time for=20
Mathieu to comment as it's his driver.

Jonathan

> ---
> Compile-tested only.
> ---
>  drivers/iio/proximity/isl29501.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
>=20
> diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl=
29501.c
> index e5e94540f404dd2c..5ae549075b27c50d 100644
> --- a/drivers/iio/proximity/isl29501.c
> +++ b/drivers/iio/proximity/isl29501.c
> @@ -232,7 +232,6 @@ static u32 isl29501_register_write(struct isl29501_pr=
ivate *isl29501,
>  				   u32 value)
>  {
>  	const struct isl29501_register_desc *reg =3D &isl29501_registers[name];
> -	u8 msb, lsb;
>  	int ret;
> =20
>  	if (!reg->msb && value > U8_MAX)
> @@ -241,22 +240,15 @@ static u32 isl29501_register_write(struct isl29501_=
private *isl29501,
>  	if (value > U16_MAX)
>  		return -ERANGE;
> =20
> -	if (!reg->msb) {
> -		lsb =3D value & 0xFF;
> -	} else {
> -		msb =3D (value >> 8) & 0xFF;
> -		lsb =3D value & 0xFF;
> -	}
> -
>  	mutex_lock(&isl29501->lock);
>  	if (reg->msb) {
>  		ret =3D i2c_smbus_write_byte_data(isl29501->client,
> -						reg->msb, msb);
> +						reg->msb, value >> 8);
>  		if (ret < 0)
>  			goto err;
>  	}
> =20
> -	ret =3D i2c_smbus_write_byte_data(isl29501->client, reg->lsb, lsb);
> +	ret =3D i2c_smbus_write_byte_data(isl29501->client, reg->lsb, value);
> =20
>  err:
>  	mutex_unlock(&isl29501->lock);

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

* Re: [PATCH] iio: light: isl29501: Simplify code to kill compiler warning
  2018-08-25  8:30 ` Jonathan Cameron
@ 2018-09-02  8:59   ` Jonathan Cameron
  2018-09-02  9:48     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2018-09-02  8:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Mathieu Othacehe, Arnd Bergmann, linux-iio, linux-kernel

On Sat, 25 Aug 2018 09:30:55 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu, 23 Aug 2018 23:24:35 +0200
> Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> 
> > With gcc 4.1.2:
> > 
> >     drivers/iio/proximity/isl29501.c: In function ‘isl29501_register_write’:
> >     drivers/iio/proximity/isl29501.c:235: warning: ‘msb’ may be used uninitialized in this function
> > 
> > While this is a false positive, it can easily be avoided by removing the
> > "msb" intermediate variable.
> > Remove the "lsb" intermediate variable for consistency.
> > 
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>  
> 
> Looks sensible to me, but I'd obviously like to leave a little time for 
> Mathieu to comment as it's his driver.
Long enough. I guess Mathieu is busy so I'll apply this (mostly before
it goes so far back in my email that I loose it)

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.  I thought about marking for stable
to reduce noise but decided that compiler is old enough (and I've not
seen it with GCC 8 IIRC) that I wouldn't bother.

Basically I'm taking this on the merits of it being better code rather 
than the warning fix :)

Thanks,

Jonathan
> 
> Jonathan
> 
> > ---
> > Compile-tested only.
> > ---
> >  drivers/iio/proximity/isl29501.c | 12 ++----------
> >  1 file changed, 2 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
> > index e5e94540f404dd2c..5ae549075b27c50d 100644
> > --- a/drivers/iio/proximity/isl29501.c
> > +++ b/drivers/iio/proximity/isl29501.c
> > @@ -232,7 +232,6 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
> >  				   u32 value)
> >  {
> >  	const struct isl29501_register_desc *reg = &isl29501_registers[name];
> > -	u8 msb, lsb;
> >  	int ret;
> >  
> >  	if (!reg->msb && value > U8_MAX)
> > @@ -241,22 +240,15 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
> >  	if (value > U16_MAX)
> >  		return -ERANGE;
> >  
> > -	if (!reg->msb) {
> > -		lsb = value & 0xFF;
> > -	} else {
> > -		msb = (value >> 8) & 0xFF;
> > -		lsb = value & 0xFF;
> > -	}
> > -
> >  	mutex_lock(&isl29501->lock);
> >  	if (reg->msb) {
> >  		ret = i2c_smbus_write_byte_data(isl29501->client,
> > -						reg->msb, msb);
> > +						reg->msb, value >> 8);
> >  		if (ret < 0)
> >  			goto err;
> >  	}
> >  
> > -	ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, lsb);
> > +	ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, value);
> >  
> >  err:
> >  	mutex_unlock(&isl29501->lock);  
> 

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

* Re: [PATCH] iio: light: isl29501: Simplify code to kill compiler warning
  2018-09-02  8:59   ` Jonathan Cameron
@ 2018-09-02  9:48     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2018-09-02  9:48 UTC (permalink / raw)
  To: jic23
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, m.othacehe,
	Arnd Bergmann, linux-iio, Linux Kernel Mailing List

Hi Jonathan,

On Sun, Sep 2, 2018 at 10:59 AM Jonathan Cameron
<jic23@jic23.retrosnub.co.uk> wrote:
> On Sat, 25 Aug 2018 09:30:55 +0100
> Jonathan Cameron <jic23@kernel.org> wrote:
>
> > On Thu, 23 Aug 2018 23:24:35 +0200
> > Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> >
> > > With gcc 4.1.2:
> > >
> > >     drivers/iio/proximity/isl29501.c: In function =E2=80=98isl29501_r=
egister_write=E2=80=99:
> > >     drivers/iio/proximity/isl29501.c:235: warning: =E2=80=98msb=E2=80=
=99 may be used uninitialized in this function
> > >
> > > While this is a false positive, it can easily be avoided by removing =
the
> > > "msb" intermediate variable.
> > > Remove the "lsb" intermediate variable for consistency.
> > >
> > > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> >
> > Looks sensible to me, but I'd obviously like to leave a little time for
> > Mathieu to comment as it's his driver.
> Long enough. I guess Mathieu is busy so I'll apply this (mostly before
> it goes so far back in my email that I loose it)
>
> Applied to the togreg branch of iio.git and pushed out as testing for
> the autobuilders to play with it.  I thought about marking for stable
> to reduce noise but decided that compiler is old enough (and I've not
> seen it with GCC 8 IIRC) that I wouldn't bother.

Thanks!

> Basically I'm taking this on the merits of it being better code rather
> than the warning fix :)

JFTR: I only send patches for these warnings if they (a) fix a real bug, or=
 (b)
improve the code.

Gr{oetje,eeting}s,

                        Geert

--=20
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k=
.org

In personal conversations with technical people, I call myself a hacker. Bu=
t
when I'm talking to journalists I just say "programmer" or something like t=
hat.
                                -- Linus Torvalds

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

end of thread, other threads:[~2018-09-02 13:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-23 21:24 [PATCH] iio: light: isl29501: Simplify code to kill compiler warning Geert Uytterhoeven
2018-08-25  8:30 ` Jonathan Cameron
2018-09-02  8:59   ` Jonathan Cameron
2018-09-02  9:48     ` Geert Uytterhoeven

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).