staging: iio: light: Fix compiler warning in tsl2563.c
Subsystems (3)
PATCH 1/1 staging: iio: light: Fix compiler warning in tsl2563.c
CC [M] drivers/staging/iio/light/tsl2563.odrivers/staging/iio/light/tsl2563.c: In function 'tsl2563_probe':drivers/staging/iio/light/tsl2563.c:736: warning: 'id' may be used uninitialized in this function
Also fixes the tsl2563_read_id().
---
drivers/staging/iio/light/tsl2563.c +8 -6
@@ -225,9 +225,9 @@ static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) ret =i2c_smbus_read_byte_data (client,TSL2563_CMD |TSL2563_REG_ID );if (ret <0 ) -return ret; +return -EIO ; -return 0 ; +return ret; }/*
@@ -697,7 +697,7 @@ static int __devinit tsl2563_probe(struct i2c_client *client,struct tsl2563_platform_data *pdata = client->dev.platform_data;int err =0 ;int ret; -u8 id; +u8 id =0 ; indio_dev =iio_allocate_device (sizeof (*chip));if (!indio_dev)
@@ -709,15 +709,17 @@ static int __devinit tsl2563_probe(struct i2c_client *client, chip->client = client; err =tsl2563_detect (chip); -if (err) { +if (err <0 ) {dev_err (&client->dev,"device not found, error %d\n" , -err); goto fail1; } err =tsl2563_read_id (chip, &id); -if (err) +if (err <0 ) { +dev_err (&client->dev,"id reading failed, error %d\n" , -err); goto fail1; - + } + id = err;mutex_init (&chip->lock);/* Default values used until userspace says otherwise */
drivers/staging/iio/light/tsl2563.c static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) · line 228
Quoted 8 lines · Maxin B. John
drivers/staging/iio/light/tsl2563.c +1
-1@@ -225,9 +225,9 @@ static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) ret =i2c_smbus_read_byte_data (client,TSL2563_CMD |TSL2563_REG_ID );if (ret <0 ) -return ret; +return -EIO ;
Don't overwrite the error code. For example, the lower layers can return -EAGAIN and that's more useful than just returning -EIO every time.
Your fix works, but it's not very clean. Just add a "*id = ret;" line before the "return 0;" and that's it. (It doesn't make sense to pass a pointer to "id" and not use it).
(In other words, don't make any changes to the tsl2563_probe() function)
drivers/staging/iio/light/tsl2563.c static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) · line 232
Quoted 5 lines
drivers/staging/iio/light/tsl2563.c +1
-1-return 0 ; +return ret; }
regards,
dan carpenter
Quoted 18 lines · Dan Carpenter
drivers/staging/iio/light/tsl2563.c static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) · line 228
Quoted 8 lines · Maxin B. John
drivers/staging/iio/light/tsl2563.c +1
-1@@ -225,9 +225,9 @@ static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) ret =i2c_smbus_read_byte_data (client,TSL2563_CMD |TSL2563_REG_ID );if (ret <0 ) -return ret; +return -EIO ;Don't overwrite the error code. For example, the lower layers can return
-EAGAINand that's more useful than just returning-EIOevery time.Your fix works, but it's not very clean. Just add a "*id = ret;" line before the "return 0;" and that's it. (It doesn't make sense to pass a pointer to "id" and not use it).
Quoted 8 lines
(In other words, don't make any changes to the
tsl2563_probe()function)drivers/staging/iio/light/tsl2563.c static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) · line 232
Quoted 5 lines
drivers/staging/iio/light/tsl2563.c +1
-1-return 0 ; +return ret; }
Yikes - I wonder why my various compilers don't throw that up. Ah well Dan's fix is indeed the right one and what was intended.
Thanks,
Jonathan