linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] staging: iio: light: Fix compiler warning in tsl2563.c
@ 2011-09-02  9:41 Maxin B. John
  2011-09-02 10:55 ` Jonathan Cameron
  0 siblings, 1 reply; 8+ messages in thread
From: Maxin B. John @ 2011-09-02  9:41 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jonathan Cameron, Bryan Freed, linux-kernel, Greg Kroah-Hartman,
	linux-iio, Arnd Bergmann, devel, Amit Kucheria

> 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.
Ahh.. Thanks a lot for explaining this.

> 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).
Dan, yes, I agree with you. This fix is much much better than what I 
had in my mind.

> Yikes - I wonder why my various compilers don't throw that up.
I guess, in "iio-blue.git" tree, the 'id = 0' suppresses this warning.

Signed-off-by: Maxin B. John <maxin.john@gmail.com>
---
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index f25243b..55012ff 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -226,7 +226,7 @@ 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;
-
+	*id = ret;
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] staging: iio: light: Fix compiler warning in tsl2563.c
@ 2011-09-01 21:24 Maxin B. John
  2011-09-01 21:55 ` Dan Carpenter
  0 siblings, 1 reply; 8+ messages in thread
From: Maxin B. John @ 2011-09-01 21:24 UTC (permalink / raw)
  To: Amit Kucheria
  Cc: Jonathan Cameron, Greg Kroah-Hartman, Bryan Freed, Arnd Bergmann,
	linux-iio, devel, linux-kernel

  CC [M]  drivers/staging/iio/light/tsl2563.o
drivers/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().

Signed-off-by: Maxin B. John <maxin.john@gmail.com>
---
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index f25243b..f8f787d 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -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 */

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

end of thread, other threads:[~2011-10-24  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-02  9:41 [PATCH] staging: iio: light: Fix compiler warning in tsl2563.c Maxin B. John
2011-09-02 10:55 ` Jonathan Cameron
2011-10-22  5:15   ` Maxin B John
2011-10-24  8:51     ` Jonathan Cameron
     [not found]       ` <20111024090143.GB3526@mwanda>
2011-10-24  9:14         ` Jonathan Cameron
     [not found]       ` <CAMhs6Yz6B_imMAthjjpymXj1garYzjFdzXfEArUwztmpgL4_hg@mail.gmail.com>
2011-10-24  9:15         ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2011-09-01 21:24 Maxin B. John
2011-09-01 21:55 ` Dan Carpenter

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