]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: light: ltr501: return proper error code from ltr501_get_gain_index()
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Mon, 2 Feb 2026 12:07:12 +0000 (14:07 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 3 Mar 2026 21:20:58 +0000 (21:20 +0000)
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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Waqar Hameed <waqar.hameed@axis.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/ltr501.c

index 022e0693983bda88f37c2a46484e66b8b46d0519..4d99ae336f61073c28b163653ecff0264c8d3f5a 100644 (file)
@@ -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;