Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: hsc030pa: Improve i2c_transfer return value handling

The i2c_transfer() function returns the number of messages
successfully transferred. The function sends 1 message but checks
for ret == 2, which can never be true.

In practice this has no impact since the caller checks ret < 0,
and the erroneous return value of 1 is not treated as an error.

Improve the return value handling to properly distinguish between
I2C errors and unexpected transfer counts.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Tested-by: Petre Rodan <petre.rodan@subdimension.ro>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
f4e466aa f7c0ea2e

+6 -1
+6 -1
drivers/iio/pressure/hsc030pa_i2c.c
··· 34 34 msg.buf = data->buffer; 35 35 36 36 ret = i2c_transfer(client->adapter, &msg, 1); 37 + if (ret < 0) 38 + return ret; 37 39 38 - return (ret == 2) ? 0 : ret; 40 + if (ret != 1) 41 + return -EIO; 42 + 43 + return 0; 39 44 } 40 45 41 46 static int hsc_i2c_probe(struct i2c_client *client)