[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aXyaCTZfJ8WC-rcq@sunspire.home.arpa>
Date: Fri, 30 Jan 2026 13:46:17 +0200
From: Petre Rodan <petre.rodan@...dimension.ro>
To: Antoniu Miclaus <antoniu.miclaus@...log.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno S?? <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return
value handling
Hello Antoniu,
On Thu, Jan 29, 2026 at 08:14:52PM +0200, Antoniu Miclaus wrote:
> 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.
thank you for the patch, much appreciated.
Tested-by: Petre Rodan <petre.rodan@...dimension.ro>
best regards,
peter
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@...log.com>
> ---
> v2:
> - Changed subject from 'Fix' to 'Improve'
> - Clarified that the bug has no practical impact
> - Used explicit if/return pattern instead of ternary
> - Dropped Fixes tag
>
> drivers/iio/pressure/hsc030pa_i2c.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/pressure/hsc030pa_i2c.c b/drivers/iio/pressure/hsc030pa_i2c.c
> index a34ef4653f34..3500bda03d75 100644
> --- a/drivers/iio/pressure/hsc030pa_i2c.c
> +++ b/drivers/iio/pressure/hsc030pa_i2c.c
> @@ -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)
> --
> 2.43.0
>
--
petre rodan
Download attachment "signature.asc" of type "application/pgp-signature" (871 bytes)
Powered by blists - more mailing lists