* [patch v3] iio: tsl4531: fix error handling in tsl4531_check_id() [not found] <55D1F82F.8020303@ti.com> @ 2015-08-18 9:16 ` Dan Carpenter 2015-08-31 15:30 ` Jonathan Cameron 0 siblings, 1 reply; 2+ messages in thread From: Dan Carpenter @ 2015-08-18 9:16 UTC (permalink / raw) To: Jonathan Cameron Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, Dan Murphy, Krzysztof Kozlowski, linux-iio, linux-kernel, kernel-janitors The tsl4531_check_id() function returned 1 on "found" and 0 on "not found" and negative error codes on failure. This was non-standard and bug prone. The caller treated all non-zero values including error codes as "found". This patch fixes it by changing the tsl4531_check_id() to return zero on success or a negative error code, and updates the caller. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> --- v3: slightly different fix again v2: different fix diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c index 2697918..cf94ec7 100644 --- a/drivers/iio/light/tsl4531.c +++ b/drivers/iio/light/tsl4531.c @@ -158,9 +158,9 @@ static int tsl4531_check_id(struct i2c_client *client) case TSL45313_ID: case TSL45315_ID: case TSL45317_ID: - return 1; - default: return 0; + default: + return -ENODEV; } } @@ -180,9 +180,10 @@ static int tsl4531_probe(struct i2c_client *client, data->client = client; mutex_init(&data->lock); - if (!tsl4531_check_id(client)) { + ret = tsl4531_check_id(client); + if (ret) { dev_err(&client->dev, "no TSL4531 sensor\n"); - return -ENODEV; + return ret; } ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL, ^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch v3] iio: tsl4531: fix error handling in tsl4531_check_id() 2015-08-18 9:16 ` [patch v3] iio: tsl4531: fix error handling in tsl4531_check_id() Dan Carpenter @ 2015-08-31 15:30 ` Jonathan Cameron 0 siblings, 0 replies; 2+ messages in thread From: Jonathan Cameron @ 2015-08-31 15:30 UTC (permalink / raw) To: Dan Carpenter Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, Dan Murphy, Krzysztof Kozlowski, linux-iio, linux-kernel, kernel-janitors On 18/08/15 10:16, Dan Carpenter wrote: > The tsl4531_check_id() function returned 1 on "found" and 0 on "not > found" and negative error codes on failure. This was non-standard and > bug prone. The caller treated all non-zero values including error codes > as "found". > > This patch fixes it by changing the tsl4531_check_id() to return zero on > success or a negative error code, and updates the caller. > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Applied to the fixes-togreg branch of iio.git. Given it's just a slightly different approach to the v2 that Peter acked, I pulled that ack in here as well. Thanks, Jonathan > --- > v3: slightly different fix again > v2: different fix > > diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c > index 2697918..cf94ec7 100644 > --- a/drivers/iio/light/tsl4531.c > +++ b/drivers/iio/light/tsl4531.c > @@ -158,9 +158,9 @@ static int tsl4531_check_id(struct i2c_client *client) > case TSL45313_ID: > case TSL45315_ID: > case TSL45317_ID: > - return 1; > - default: > return 0; > + default: > + return -ENODEV; > } > } > > @@ -180,9 +180,10 @@ static int tsl4531_probe(struct i2c_client *client, > data->client = client; > mutex_init(&data->lock); > > - if (!tsl4531_check_id(client)) { > + ret = tsl4531_check_id(client); > + if (ret) { > dev_err(&client->dev, "no TSL4531 sensor\n"); > - return -ENODEV; > + return ret; > } > > ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL, > ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-08-31 15:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <55D1F82F.8020303@ti.com>
2015-08-18 9:16 ` [patch v3] iio: tsl4531: fix error handling in tsl4531_check_id() Dan Carpenter
2015-08-31 15:30 ` Jonathan Cameron
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox