[PATCH v2] iio: light: ltr501: return proper error code from ltr501_get_gain_index()
From: Antoniu Miclaus
Date: Mon Feb 02 2026 - 07:14:40 EST
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@xxxxxxxxxx>
---
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