]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: pressure: hsc030pa: Improve i2c_transfer return value handling
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Thu, 29 Jan 2026 18:14:52 +0000 (20:14 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 3 Mar 2026 21:20:00 +0000 (21:20 +0000)
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>
drivers/iio/pressure/hsc030pa_i2c.c

index a34ef4653f342a3265b3a88d0f7291586a89a0ec..3500bda03d750f181c9ea054126877c0667621ce 100644 (file)
@@ -34,8 +34,13 @@ static int hsc_i2c_recv(struct hsc_data *data)
        msg.buf = data->buffer;
 
        ret = i2c_transfer(client->adapter, &msg, 1);
+       if (ret < 0)
+               return ret;
 
-       return (ret == 2) ? 0 : ret;
+       if (ret != 1)
+               return -EIO;
+
+       return 0;
 }
 
 static int hsc_i2c_probe(struct i2c_client *client)