public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index()
@ 2026-02-02 12:07 Antoniu Miclaus
  2026-02-02 12:25 ` Waqar Hameed
  2026-02-03  8:27 ` Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-02-02 12:07 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Waqar Hameed, chuguangqing, Antoniu Miclaus, linux-iio,
	linux-kernel

Return -EINVAL instead of -1 when no matching gain value is found
in the gain table. Update the callers to propagate this error directly
rather than overwriting it with -EINVAL.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v2:
 - Update callers to propagate the error directly instead of
   overwriting it with -EINVAL.

 drivers/iio/light/ltr501.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 022e0693983b..4d99ae336f61 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -754,7 +754,7 @@ static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size,
 		if (val == gain[i].scale && val2 == gain[i].uscale)
 			return i;
 
-	return -1;
+	return -EINVAL;
 }
 
 static int __ltr501_write_raw(struct iio_dev *indio_dev,
@@ -773,7 +773,7 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
 						  info->als_gain_tbl_size,
 						  val, val2);
 			if (i < 0)
-				return -EINVAL;
+				return i;
 
 			data->als_contr &= ~info->als_gain_mask;
 			data->als_contr |= i << info->als_gain_shift;
@@ -785,7 +785,7 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
 						  info->ps_gain_tbl_size,
 						  val, val2);
 			if (i < 0)
-				return -EINVAL;
+				return i;
 
 			data->ps_contr &= ~LTR501_CONTR_PS_GAIN_MASK;
 			data->ps_contr |= i << LTR501_CONTR_PS_GAIN_SHIFT;
-- 
2.43.0


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

* Re: [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index()
  2026-02-02 12:07 [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index() Antoniu Miclaus
@ 2026-02-02 12:25 ` Waqar Hameed
  2026-02-03  8:27 ` Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Waqar Hameed @ 2026-02-02 12:25 UTC (permalink / raw)
  To: Antoniu Miclaus
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	chuguangqing, linux-iio, linux-kernel

On Mon, Feb 02, 2026 at 14:07 +0200 Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:

> Return -EINVAL instead of -1 when no matching gain value is found
> in the gain table. Update the callers to propagate this error directly
> rather than overwriting it with -EINVAL.
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---
> Changes in v2:
>  - Update callers to propagate the error directly instead of
>    overwriting it with -EINVAL.

For future reference, it's good practice to also have a link to v1. (No
need to resend for that)

>
>  drivers/iio/light/ltr501.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 022e0693983b..4d99ae336f61 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -754,7 +754,7 @@ static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size,
>  		if (val == gain[i].scale && val2 == gain[i].uscale)
>  			return i;
>  
> -	return -1;
> +	return -EINVAL;
>  }
>  
>  static int __ltr501_write_raw(struct iio_dev *indio_dev,
> @@ -773,7 +773,7 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
>  						  info->als_gain_tbl_size,
>  						  val, val2);
>  			if (i < 0)
> -				return -EINVAL;
> +				return i;
>  
>  			data->als_contr &= ~info->als_gain_mask;
>  			data->als_contr |= i << info->als_gain_shift;
> @@ -785,7 +785,7 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
>  						  info->ps_gain_tbl_size,
>  						  val, val2);
>  			if (i < 0)
> -				return -EINVAL;
> +				return i;
>  
>  			data->ps_contr &= ~LTR501_CONTR_PS_GAIN_MASK;
>  			data->ps_contr |= i << LTR501_CONTR_PS_GAIN_SHIFT;

This return-pattern is similar to how it is used in the other `case`s in
this function. Consistency is a nice trait to have in code :)

Reviewed-by: Waqar Hameed <waqar.hameed@axis.com>

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

* Re: [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index()
  2026-02-02 12:07 [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index() Antoniu Miclaus
  2026-02-02 12:25 ` Waqar Hameed
@ 2026-02-03  8:27 ` Andy Shevchenko
  2026-02-07 15:54   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-03  8:27 UTC (permalink / raw)
  To: Antoniu Miclaus
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Waqar Hameed, chuguangqing, linux-iio, linux-kernel

On Mon, Feb 02, 2026 at 02:07:12PM +0200, Antoniu Miclaus wrote:
> Return -EINVAL instead of -1 when no matching gain value is found
> in the gain table. Update the callers to propagate this error directly
> rather than overwriting it with -EINVAL.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

...

> static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size,

>  		if (val == gain[i].scale && val2 == gain[i].uscale)
>  			return i;
>  
> -	return -1;
> +	return -EINVAL;

I would use -ENOENT, but I'm not sure if there is any ABI involved (id est we
return this to user space).

>  }


-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index()
  2026-02-03  8:27 ` Andy Shevchenko
@ 2026-02-07 15:54   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-02-07 15:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Antoniu Miclaus, David Lechner, Nuno Sá, Andy Shevchenko,
	Waqar Hameed, chuguangqing, linux-iio, linux-kernel

On Tue, 3 Feb 2026 10:27:23 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Feb 02, 2026 at 02:07:12PM +0200, Antoniu Miclaus wrote:
> > Return -EINVAL instead of -1 when no matching gain value is found
> > in the gain table. Update the callers to propagate this error directly
> > rather than overwriting it with -EINVAL.  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> ...
> 
> > static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size,  
> 
> >  		if (val == gain[i].scale && val2 == gain[i].uscale)
> >  			return i;
> >  
> > -	return -1;
> > +	return -EINVAL;  
> 
> I would use -ENOENT, but I'm not sure if there is any ABI involved (id est we
> return this to user space).
It will surface.  Not sure anyone would notice the change, but lets
keep things simple.

Applied.

Jonathan

> 
> >  }  
> 
> 


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

end of thread, other threads:[~2026-02-07 15:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 12:07 [PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index() Antoniu Miclaus
2026-02-02 12:25 ` Waqar Hameed
2026-02-03  8:27 ` Andy Shevchenko
2026-02-07 15:54   ` Jonathan Cameron

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