public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return value handling
@ 2026-01-29 18:14 Antoniu Miclaus
  2026-01-30 11:46 ` Petre Rodan
  0 siblings, 1 reply; 3+ messages in thread
From: Antoniu Miclaus @ 2026-01-29 18:14 UTC (permalink / raw)
  To: Petre Rodan, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel
  Cc: Antoniu Miclaus

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>
---
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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return value handling
  2026-01-29 18:14 [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return value handling Antoniu Miclaus
@ 2026-01-30 11:46 ` Petre Rodan
  2026-01-31 17:14   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Petre Rodan @ 2026-01-30 11:46 UTC (permalink / raw)
  To: Antoniu Miclaus
  Cc: Jonathan Cameron, David Lechner, Nuno S??, Andy Shevchenko,
	linux-iio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1634 bytes --]


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@subdimension.ro>

best regards,
peter

> 
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 870 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return value handling
  2026-01-30 11:46 ` Petre Rodan
@ 2026-01-31 17:14   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-01-31 17:14 UTC (permalink / raw)
  To: Petre Rodan
  Cc: Antoniu Miclaus, David Lechner, Nuno S??, Andy Shevchenko,
	linux-iio, linux-kernel

On Fri, 30 Jan 2026 13:46:17 +0200
Petre Rodan <petre.rodan@subdimension.ro> wrote:

> 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@subdimension.ro>
Applied and pushed out as testing. This is 7.1 material now.

J
> 
> best regards,
> peter
> 
> > 
> > Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.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
> >   
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-31 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 18:14 [PATCH v2] iio: pressure: hsc030pa: Improve i2c_transfer return value handling Antoniu Miclaus
2026-01-30 11:46 ` Petre Rodan
2026-01-31 17:14   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox