iio: light: isl29501: Simplify code to kill compiler warning
PATCH 1/1 iio: light: isl29501: Simplify code to kill compiler warning
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.
---
Compile-tested only.
--- drivers/iio/proximity/isl29501.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/iio/proximity/isl29501.c +2 -10
@@ -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);
Signature · 1 line
2.17.1
Jonathan Cameron
maintainerQuoted 10 lines · On Thu, 23 Aug 2018 23:24:35 +0200 Geert Uytterhoeven <[email protected]>…
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 functionWhile 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 <[email protected]>
Looks sensible to me, but I'd obviously like to leave a little time for Mathieu to comment as it's his driver.
Jonathan
Quoted 43 lines
---
Compile-tested only.--- drivers/iio/proximity/isl29501.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/iio/proximity/isl29501.c +2
-10@@ -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);
Quoted 8 lines · On Sat, 25 Aug 2018 09:30:55 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Thu, 23 Aug 2018 23:24:35 +0200 Geert Uytterhoeven <[email protected]>…
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
Quoted 8 lines
Quoted 5 lines
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 <[email protected]>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
Quoted 47 lines
Jonathan
Quoted 43 lines
---
Compile-tested only.--- drivers/iio/proximity/isl29501.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/iio/proximity/isl29501.c +2
-10@@ -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);
Hi Jonathan,
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Sat, 25 Aug 2018 09:30:55 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 3 lines · On Thu, 23 Aug 2018 23:24:35 +0200 Geert Uytterhoeven <[email protected]>…
With gcc 4.1.2:
drivers/iio/proximity/isl29501.c: In function =E2=80=98isl29501_r=
egister_write=E2=80=99:
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/iio/proximity/isl29501.c:235: warning: =E2=80=98msb=E2=80=
=99 may be used uninitialized in this function
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
While this is a false positive, it can easily be avoided by removing =
the
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
"msb" intermediate variable.
Remove the "lsb" intermediate variable for consistency.Signed-off-by Geert Uytterhoeven <[email protected]>Looks sensible to me, but I'd obviously like to leave a little time for Mathieu to comment as it's his driver.
Quoted 7 lines
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!
Quoted 2 lines
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