Skip to contentSkip to conversation

iio: light: ltr501: return proper error code from ltr501_get_gain_index()

PATCH Applied Antoniu Miclaus 4 participants 4 messages Feb 2 – Feb 7 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: light: ltr501: return proper error code from ltr501_get_gain_index()

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.

---
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(-)
drivers/iio/light/ltr501.c +3 -3
index 022e0693983b..4d99ae336f61 100644
@@ -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;
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · On Mon, Feb 02, 2026 at 14:07 +0200 Antoniu Miclaus…

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.

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

Quoted 27 lines
 drivers/iio/light/ltr501.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/light/ltr501.c +2 -2
index 022e0693983b..4d99ae336f61 100644
@@ -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;

drivers/iio/light/ltr501.c static int __ltr501_write_raw(struct iio_dev *indio_dev, · line 791

Quoted 8 lines
drivers/iio/light/ltr501.c +1 -1
@@ -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 cases in this function. Consistency is a nice trait to have in code :)

Reviewed-by on v2 1/1
#2 lore raw
In reply to Antoniu Miclaus
Quoted 3 lines · Antoniu Miclaus

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.

...

drivers/iio/light/ltr501.c static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size, · line 757

Quoted 7 lines

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

drivers/iio/light/ltr501.c +1 -1
 		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).

Quoted 1 line

}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#3 lore raw
Quoted 11 lines · On Tue, 3 Feb 2026 10:27:23 +0200 Andy Shevchenko…
Quoted 3 lines · Antoniu Miclaus

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.

...

Quoted 1 line

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

Quoted 8 lines

drivers/iio/light/ltr501.c static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size, · line 757

Quoted 5 lines
drivers/iio/light/ltr501.c +1 -1
 		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

Quoted 4 lines
Quoted 2 lines

}