From: Dan Carpenter Date: Tue, 18 Aug 2015 09:16:33 +0000 (+0300) Subject: iio: tsl4531: fix error handling in tsl4531_check_id() X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=7d87b3c5c8602df4ce6d615b33ae6dc15438fa29;p=deliverable%2Flinux.git iio: tsl4531: fix error handling in tsl4531_check_id() 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 Acked-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c index 26979183d27c..cf94ec72b181 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,