Skip to contentSkip to conversation

iio: Unshadow error codes in ->store()

PATCH Applied Andy Shevchenko 6 participants 21 messages Aug 13 – Aug 22

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover iio: Unshadow error codes in ->store()

kstrtox() may return different error codes. Allow them to be returned. This mini-series makes all IIO drivers to follow the same pattern when using kstrtox() APIs. Patches can be individually applied, the series is just a union by the subject, no code dependencies are there.

Andy Shevchenko (4):
iio: light: Unshadow error codes in ->store()
iio: imu: inv_mpu6050: Unshadow error codes in ->store()
iio: chemical: sps30: Unshadow error codes in ->store()
iio: adc: pac1934: Unshadow error codes in ->store()

 drivers/iio/adc/pac1934.c                  |  9 ++++++---
 drivers/iio/chemical/sps30.c               | 11 ++++++++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  6 ++++--
 drivers/iio/light/isl29018.c               |  7 +++++--
 drivers/iio/light/lm3533-als.c             | 11 +++++++----
 drivers/iio/light/tsl2583.c                | 15 +++++++++++----
 drivers/iio/light/tsl2772.c                | 16 ++++++++++++----
 7 files changed, 53 insertions(+), 22 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/4 iio: light: Unshadow error codes in ->store()

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/light/isl29018.c   |  7 +++++--
 drivers/iio/light/lm3533-als.c | 11 +++++++----
 drivers/iio/light/tsl2583.c    | 15 +++++++++++----
 drivers/iio/light/tsl2772.c    | 16 ++++++++++++----
 4 files changed, 35 insertions(+), 14 deletions(-)
drivers/iio/light/isl29018.c +5 -2
index 759cb71ed1c5..7f7a563df4d9 100644
@@ -10,6 +10,7 @@
 
 #include <linux/i2c.h>
 #include <linux/err.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/delay.h>
@@ -339,9 +340,11 @@ static ssize_t proximity_on_chip_ambient_infrared_suppression_store
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct isl29018_chip *chip = iio_priv(indio_dev);
 	int val;
+	int ret;
 
-	if (kstrtoint(buf, 10, &val))
-		return -EINVAL;
+	ret = kstrtoint(buf, 10, &val);
+	if (ret)
+		return ret;
 	if (!(val == 0 || val == 1))
 		return -EINVAL;
 
drivers/iio/light/lm3533-als.c +7 -4
index 99f0b903018c..5db9591a85b9 100644
@@ -13,6 +13,7 @@
 #include <linux/io.h>
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/mfd/core.h>
@@ -434,8 +435,9 @@ static ssize_t store_thresh_either_en(struct device *dev,
 	if (!als->irq)
 		return -EBUSY;
 
-	if (kstrtoul(buf, 0, &enable))
-		return -EINVAL;
+	ret = kstrtoul(buf, 0, &enable);
+	if (ret)
+		return ret;
 
 	int_enabled = test_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags);
 
@@ -542,8 +544,9 @@ static ssize_t store_als_attr(struct device *dev,
 	u8 val;
 	int ret;
 
-	if (kstrtou8(buf, 0, &val))
-		return -EINVAL;
+	ret = kstrtou8(buf, 0, &val);
+	if (ret)
+		return ret;
 
 	switch (als_attr->type) {
 	case LM3533_ATTR_TYPE_TARGET:
drivers/iio/light/tsl2583.c +11 -4
index 53fd423aa7ae..2d041b7530e6 100644
@@ -7,10 +7,11 @@
  * Copyright (c) 2016-2017 Brian Masney <[email protected]>
  */
 
-#include <linux/kernel.h>
 #include <linux/i2c.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/kstrtox.h>
 #include <linux/string.h>
 #include <linux/mutex.h>
 #include <linux/unistd.h>
@@ -483,9 +484,12 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int value;
+	int value, ret;
 
-	if (kstrtoint(buf, 0, &value) || !value)
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
@@ -503,7 +507,10 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	int value, ret;
 
-	if (kstrtoint(buf, 0, &value) || value != 1)
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
+	if (value != 1)
 		return -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
drivers/iio/light/tsl2772.c +12 -4
index 4486a1d9d84d..c8a7afc65c1f 100644
@@ -13,6 +13,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/property.h>
@@ -951,8 +952,9 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 	u16 value;
 	int ret;
 
-	if (kstrtou16(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtou16(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	chip->settings.als_cal_target = value;
 	ret = tsl2772_invoke_change(indio_dev);
@@ -970,7 +972,10 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (kstrtobool(buf, &value) || !value)
+	ret = kstrtobool(buf, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	ret = tsl2772_als_calibrate(indio_dev);
@@ -1061,7 +1066,10 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (kstrtobool(buf, &value) || !value)
+	ret = kstrtobool(buf, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	ret = tsl2772_prox_cal(indio_dev);
Signature · 1 line
2.50.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 14 lines · CDT Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/light/isl29018.c   |  7 +++++--
 drivers/iio/light/lm3533-als.c | 11 +++++++----
 drivers/iio/light/tsl2583.c    | 15 +++++++++++----
 drivers/iio/light/tsl2772.c    | 16 ++++++++++++----
 4 files changed, 35 insertions(+), 14 deletions(-)

...

drivers/iio/light/tsl2583.c line 13

Quoted 13 lines
drivers/iio/light/tsl2583.c +1 -1
index 53fd423aa7ae..2d041b7530e6 100644
@@ -7,10 +7,11 @@
  * Copyright (c) 2016-2017 Brian Masney <[email protected]>
  */
 
-#include <linux/kernel.h>
 #include <linux/i2c.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <linux/kernel.h>

Stray change? The ordering's messed up (seems to be case for many of these drivers) so perhaps we can send a patch to fix the ordering.

Otherwise,

thanks,
max

Quoted 79 lines
drivers/iio/light/tsl2583.c +10 -3
+#include <linux/kstrtox.h>
 #include <linux/string.h>
 #include <linux/mutex.h>
 #include <linux/unistd.h>
@@ -483,9 +484,12 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int value;
+	int value, ret;
 
-	if (kstrtoint(buf, 0, &value) || !value)
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
@@ -503,7 +507,10 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	int value, ret;
 
-	if (kstrtoint(buf, 0, &value) || value != 1)
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
+	if (value != 1)
 		return -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
drivers/iio/light/tsl2772.c +12 -4
index 4486a1d9d84d..c8a7afc65c1f 100644
@@ -13,6 +13,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/property.h>
@@ -951,8 +952,9 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 	u16 value;
 	int ret;
 
-	if (kstrtou16(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtou16(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	chip->settings.als_cal_target = value;
 	ret = tsl2772_invoke_change(indio_dev);
@@ -970,7 +972,10 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (kstrtobool(buf, &value) || !value)
+	ret = kstrtobool(buf, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	ret = tsl2772_als_calibrate(indio_dev);
@@ -1061,7 +1066,10 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (kstrtobool(buf, &value) || !value)
+	ret = kstrtobool(buf, &value);
+	if (ret)
+		return ret;
+	if (!value)
 		return -EINVAL;
 
 	ret = tsl2772_prox_cal(indio_dev);
#3 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 2 lines · Maxwell Doose

On Thu Aug 13, 2026 at 2:16 AM CDT
Andy Shevchenko <[email protected]> wrote:

...

Quoted 8 lines

drivers/iio/light/tsl2583.c line 13

Quoted 5 lines
drivers/iio/light/tsl2583.c +1 -1
-#include <linux/kernel.h>
 #include <linux/i2c.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <linux/kernel.h>

Stray change? The ordering's messed up (seems to be case for many of these drivers) so perhaps we can send a patch to fix the ordering.

Not really. I understand what you mean, but I took a step just for the k*.h letter to group them. It's slightly easier to follow with kernel.h being moved. Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Quoted 4 lines
Quoted 4 lines

+#include <linux/kstrtox.h>
#include <linux/string.h>
#include <linux/mutex.h>
#include <linux/unistd.h>

Thanks for the review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 15 lines · CDT Andy Shevchenko
Quoted 2 lines · Maxwell Doose

On Thu Aug 13, 2026 at 2:16 AM CDT
Andy Shevchenko <[email protected]> wrote:

...

Quoted 8 lines

drivers/iio/light/tsl2583.c line 13

Quoted 5 lines
drivers/iio/light/tsl2583.c +1 -1
-#include <linux/kernel.h>
 #include <linux/i2c.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <linux/kernel.h>

Stray change? The ordering's messed up (seems to be case for many of these drivers) so perhaps we can send a patch to fix the ordering.

Quoted 2 lines

Not really. I understand what you mean, but I took a step just for the k*.h letter to group them. It's slightly easier to follow with

Fair enough :)

Quoted 2 lines

kernel.h being moved. Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

thanks,
max

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

+#include <linux/kstrtox.h>
#include <linux/string.h>
#include <linux/mutex.h>
#include <linux/unistd.h>

Thanks for the review!

#5 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 3 lines · Maxwell Doose
Quoted 1 line · CDT Andy Shevchenko

On Thu, Aug 13, 2026 at 8:52 PM Maxwell Doose <[email protected]> wrote:

...

Quoted 6 lines
Quoted 2 lines

Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

Yes, for sure! I have simply had no time to do it myself, but I have a low-prio item in my always grown TODO list. So, if you do that, I will really appreciate! But be careful, the actual patches should care about the whole bunch of the inclusions, and not just about kernel.h. This means each driver should be carefully inspected in accordance with the IWYU principles.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 15 lines · Andy Shevchenko
Quoted 3 lines · Maxwell Doose
Quoted 1 line · CDT Andy Shevchenko

On Thu, Aug 13, 2026 at 8:52 PM Maxwell Doose <[email protected]> wrote:

...

Quoted 6 lines
Quoted 2 lines

Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

Quoted 5 lines

Yes, for sure! I have simply had no time to do it myself, but I have a low-prio item in my always grown TODO list. So, if you do that, I will really appreciate! But be careful, the actual patches should care about the whole bunch of the inclusions, and not just about kernel.h. This means each driver should be carefully inspected in accordance with the IWYU principles.

This will be a gruelling task (implementing and reviewing), but perhaps it would be easier to do one sensor type at a time instead of the entire subsystem.

--
Kind regards,
Joshua Crofts

#7 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 6 lines · Joshua Crofts
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Maxwell Doose
Quoted 1 line · CDT Andy Shevchenko

On Thu, Aug 13, 2026 at 8:52 PM Maxwell Doose <[email protected]> wrote:

...

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

Quoted 5 lines

Yes, for sure! I have simply had no time to do it myself, but I have a low-prio item in my always grown TODO list. So, if you do that, I will really appreciate! But be careful, the actual patches should care about the whole bunch of the inclusions, and not just about kernel.h. This means each driver should be carefully inspected in accordance with the IWYU principles.

Quoted 3 lines

This will be a gruelling task (implementing and reviewing), but perhaps it would be easier to do one sensor type at a time instead of the entire subsystem.

I would start from the easy cases where kernel.h is just not used at all (not even as a "proxy" header). Then continue with the rest.

Joshua, note, it's only about the drivers that have explicit kernel.h inclusion. In general the entire IIO needs to be revisited, indeed.

$ git grep -n -lw linux/kernel.h -- drivers/iio/ | wc -l
234
$ git ls-files | grep ^drivers/iio/.*\.c$ | wc -l
707
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 23 lines · On Fri, 14 Aug 2026 11:50:57 +0300 Andy Shevchenko…
Quoted 6 lines · Joshua Crofts
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Maxwell Doose
Quoted 1 line · CDT Andy Shevchenko

On Thu, Aug 13, 2026 at 8:52 PM Maxwell Doose <[email protected]> wrote:

...

Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
Quoted 2 lines

Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

Yes, for sure! I have simply had no time to do it myself, but I have a low-prio item in my always grown TODO list. So, if you do that, I will really appreciate! But be careful, the actual patches should care about the whole bunch of the inclusions, and not just about kernel.h. This means each driver should be carefully inspected in accordance with the IWYU principles.

Quoted 3 lines
Quoted 3 lines

This will be a gruelling task (implementing and reviewing), but perhaps it would be easier to do one sensor type at a time instead of the entire subsystem.

Absolutely. One patch per driver for this and not more than 10 ish drivers in a series or out for review at a tiem. This stuff is still quite tricky to review, even with details on why each header change below the ---

Also precursor patches for any significant reordering to put them in alphabetical
+ block for IIO headers just to make it easier to read the patch that cleans up what is included.

I've done some of these as have many others. It's worthy work but slow to do! I'd suggest we leave it as a newbie task, but it requires more understanding than typical for one of those - so if you want to take it on (probably take a year or more to finish given review bandwidth!) then that would be most welcome.

Quoted 3 lines

I would start from the easy cases where kernel.h is just not used at all (not even as a "proxy" header). Then continue with the rest.

yeah - if there are cheap ones were we can just drop it and now do the rest of the work then I don't mind seeing those on their own.

Jonathan

Quoted 10 lines

Joshua, note, it's only about the drivers that have explicit kernel.h inclusion. In general the entire IIO needs to be revisited, indeed.

$ git grep -n -lw linux/kernel.h -- drivers/iio/ | wc -l
234
$ git ls-files | grep ^drivers/iio/.*\.c$ | wc -l
707
#9 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 37 lines · CDT Jonathan Cameron
Quoted 23 lines · On Fri, 14 Aug 2026 11:50:57 +0300 Andy Shevchenko…
Quoted 6 lines · Joshua Crofts
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Maxwell Doose
Quoted 1 line · CDT Andy Shevchenko

On Thu, Aug 13, 2026 at 8:52 PM Maxwell Doose <[email protected]> wrote:

...

Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
Quoted 2 lines

Note, that kernel.h shouldn't be there at all, but that is definitely out of scope here.

Makes sense. I wonder if it may be worth doing a patch series removing all of the kernel.h inclusions in IIO all at once (or maybe some drivers have a legitimate use for it, but that seems highly unlikely).

Yes, for sure! I have simply had no time to do it myself, but I have a low-prio item in my always grown TODO list. So, if you do that, I will really appreciate! But be careful, the actual patches should care about the whole bunch of the inclusions, and not just about kernel.h. This means each driver should be carefully inspected in accordance with the IWYU principles.

Quoted 3 lines
Quoted 3 lines

This will be a gruelling task (implementing and reviewing), but perhaps it would be easier to do one sensor type at a time instead of the entire subsystem.

Absolutely. One patch per driver for this and not more than 10 ish drivers in a series or out for review at a tiem. This stuff is still quite tricky to review, even with details on why each header change below the ---

Also precursor patches for any significant reordering to put them in alphabetical
+ block for IIO headers just to make it easier to read the patch that cleans up what is included.

Quoted 6 lines

I've done some of these as have many others. It's worthy work but slow to do! I'd suggest we leave it as a newbie task, but it requires more understanding than typical for one of those - so if you want to take it on (probably take a year or more to finish given review bandwidth!) then that would be most welcome.

What we ought to do is start by removing all of the kernel.h inclusions and then we can go into each individual driver and do IWYU on them. Not sure if we want all of the IWYU stuff (including kernel.h removal) rolled up into one patch per driver or if we want to split patches into kernel.h removal and then IWYU (hopefully this time I can get iwyu-tool setup so it won't be *as* gruelling). Or in the case of we leave it as a newbie task maybe we just add it to the TODO (since this is probably one of those things that happens over time when we revisit drivers).

thanks,
max

Quoted 18 lines
Quoted 3 lines

I would start from the easy cases where kernel.h is just not used at all (not even as a "proxy" header). Then continue with the rest.

yeah - if there are cheap ones were we can just drop it and now do the rest of the work then I don't mind seeing those on their own.

Jonathan

Quoted 10 lines

Joshua, note, it's only about the drivers that have explicit kernel.h inclusion. In general the entire IIO needs to be revisited, indeed.

$ git grep -n -lw linux/kernel.h -- drivers/iio/ | wc -l
234
$ git ls-files | grep ^drivers/iio/.*\.c$ | wc -l
707
#10 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

On Mon, 17 Aug 2026 14:12:56 -0500
"Maxwell Doose" <[email protected]> wrote:

...

Quoted 15 lines
Quoted 8 lines

Absolutely. One patch per driver for this and not more than 10 ish drivers in a series or out for review at a tiem. This stuff is still quite tricky to review, even with details on why each header change below the ---

Also precursor patches for any significant reordering to put them in alphabetical
+ block for IIO headers just to make it easier to read the patch that cleans up what is included.

Quoted 6 lines

I've done some of these as have many others. It's worthy work but slow to do! I'd suggest we leave it as a newbie task, but it requires more understanding than typical for one of those - so if you want to take it on (probably take a year or more to finish given review bandwidth!) then that would be most welcome.

Quoted 8 lines

What we ought to do is start by removing all of the kernel.h inclusions and then we can go into each individual driver and do IWYU on them. Not sure if we want all of the IWYU stuff (including kernel.h removal) rolled up into one patch per driver or if we want to split patches into kernel.h removal and then IWYU (hopefully this time I can get iwyu-tool setup so it won't be *as* gruelling). Or in the case of we leave it as a newbie task maybe we just add it to the TODO (since this is probably one of those things that happens over time when we revisit drivers).

Well, removing kernel.h is essentially IWYU, as we have to include the actual used headers we were pulling in transitively. It should definitely be a task for newcomers, nevertheless as Jonathan says it's not exactly easy to do from the get go (and automating it with iwyu-tool can also be a headache). Also, I've had a pretty good experience with AI when it comes to verifying headers.

I'll probably send a series removing it from some sensor type subdirectory, just to get the ball rolling?

Signature · 2 lines
Kind regards,
Joshua Crofts
maintainer
#11 lore raw

Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

Quoted 29 lines · On Tue, 18 Aug 2026 16:11:15 +0200 Joshua Crofts <[email protected]>…

On Mon, 17 Aug 2026 14:12:56 -0500
"Maxwell Doose" <[email protected]> wrote:

...

Quoted 15 lines
Quoted 8 lines

Absolutely. One patch per driver for this and not more than 10 ish drivers in a series or out for review at a tiem. This stuff is still quite tricky to review, even with details on why each header change below the ---

Also precursor patches for any significant reordering to put them in alphabetical
+ block for IIO headers just to make it easier to read the patch that cleans up what is included.

Quoted 6 lines

I've done some of these as have many others. It's worthy work but slow to do! I'd suggest we leave it as a newbie task, but it requires more understanding than typical for one of those - so if you want to take it on (probably take a year or more to finish given review bandwidth!) then that would be most welcome.

Quoted 8 lines

What we ought to do is start by removing all of the kernel.h inclusions and then we can go into each individual driver and do IWYU on them. Not sure if we want all of the IWYU stuff (including kernel.h removal) rolled up into one patch per driver or if we want to split patches into kernel.h removal and then IWYU (hopefully this time I can get iwyu-tool setup so it won't be *as* gruelling). Or in the case of we leave it as a newbie task maybe we just add it to the TODO (since this is probably one of those things that happens over time when we revisit drivers).

Quoted 8 lines

Well, removing kernel.h is essentially IWYU, as we have to include the actual used headers we were pulling in transitively. It should definitely be a task for newcomers, nevertheless as Jonathan says it's not exactly easy to do from the get go (and automating it with iwyu-tool can also be a headache). Also, I've had a pretty good experience with AI when it comes to verifying headers.

I'll probably send a series removing it from some sensor type subdirectory, just to get the ball rolling?

Definitely need to include the kernel.h removal as part of iwyu, otherwise we may well run into random build issues.

Yes, a series - one per driver for a specific sensor type directory would be a good starting point. Split the bigger ones up into multiple series to keep the numbers manageable.

Jonathan

Quoted 1 line
#12 lore raw

PATCH 2/4 iio: imu: inv_mpu6050: Unshadow error codes in ->store()

In reply to Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +4 -2
index 5796896d54cd..38c3f3b398d4 100644
@@ -13,6 +13,7 @@
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/acpi.h>
+#include <linux/kstrtox.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/math64.h>
@@ -1303,8 +1304,9 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr,
 	struct inv_mpu6050_state *st = iio_priv(indio_dev);
 	struct device *pdev = regmap_get_device(st->map);
 
-	if (kstrtoint(buf, 10, &fifo_rate))
-		return -EINVAL;
+	result = kstrtoint(buf, 10, &fifo_rate);
+	if (result)
+		return result;
 	if (fifo_rate < INV_MPU6050_MIN_FIFO_RATE ||
 	    fifo_rate > INV_MPU6050_MAX_FIFO_RATE)
 		return -EINVAL;
Signature · 1 line
2.50.1
Reviewed-by on v1 2/4
#13 lore raw

Re: [PATCH v1 2/4] iio: imu: inv_mpu6050: Unshadow error codes in ->store()

Quoted 24 lines · CDT Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1 -0
index 5796896d54cd..38c3f3b398d4 100644
@@ -13,6 +13,7 @@
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/acpi.h>
+#include <linux/kstrtox.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/math64.h>

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, · line 1309

Quoted 8 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +3 -2
@@ -1303,8 +1304,9 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr,
 	struct inv_mpu6050_state *st = iio_priv(indio_dev);
 	struct device *pdev = regmap_get_device(st->map);
 
-	if (kstrtoint(buf, 10, &fifo_rate))
-		return -EINVAL;
+	result = kstrtoint(buf, 10, &fifo_rate);
+	if (result)
+		return result;

I suppose result is what was being used before? Oh well doesn't seem worth it to send a patch *just* to change to int ret.

thanks,
max

Quoted 3 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -0
 	if (fifo_rate < INV_MPU6050_MIN_FIFO_RATE ||
 	    fifo_rate > INV_MPU6050_MAX_FIFO_RATE)
 		return -EINVAL;
#14 lore raw

Re: [PATCH v1 2/4] iio: imu: inv_mpu6050: Unshadow error codes in ->store()

Quoted 2 lines · Maxwell Doose

On Thu Aug 13, 2026 at 2:16 AM CDT
Andy Shevchenko <[email protected]> wrote:

...

Quoted 5 lines

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, · line 1309

Quoted 3 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +3 -0
+     result = kstrtoint(buf, 10, &fifo_rate);
+     if (result)
+             return result;

I suppose result is what was being used before?

Yes, its semantic is the same as for the usual 'ret' variable.

Quoted 4 lines

Oh well doesn't seem
worth it to send a patch *just* to change to int ret.

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

PATCH 3/4 iio: chemical: sps30: Unshadow error codes in ->store()

In reply to Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/chemical/sps30.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/chemical/sps30.c +8 -3
index 8e15baa31423..b47d08ab4d0f 100644
@@ -15,6 +15,7 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 #include <linux/kernel.h>
+#include <linux/kstrtox.h>
 #include <linux/module.h>
 
 #include "sps30.h"
@@ -193,7 +194,10 @@ static ssize_t start_cleaning_store(struct device *dev,
 	struct sps30_state *state = iio_priv(indio_dev);
 	int val, ret;
 
-	if (kstrtoint(buf, 0, &val) || val != 1)
+	ret = kstrtoint(buf, 0, &val);
+	if (ret)
+		return ret;
+	if (val != 1)
 		return -EINVAL;
 
 	guard(mutex)(&state->lock);
@@ -230,8 +234,9 @@ static ssize_t cleaning_period_store(struct device *dev, struct device_attribute
 	struct sps30_state *state = iio_priv(indio_dev);
 	int val, ret;
 
-	if (kstrtoint(buf, 0, &val))
-		return -EINVAL;
+	ret = kstrtoint(buf, 0, &val);
+	if (ret)
+		return ret;
 
 	if ((val < SPS30_AUTO_CLEANING_PERIOD_MIN) ||
 	    (val > SPS30_AUTO_CLEANING_PERIOD_MAX))
Signature · 1 line
2.50.1
Reviewed-by on v1 3/4
#16 lore raw

Re: [PATCH v1 3/4] iio: chemical: sps30: Unshadow error codes in ->store()

Quoted 11 lines · CDT Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/chemical/sps30.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

thanks,
max

#17 lore raw

PATCH 4/4 iio: adc: pac1934: Unshadow error codes in ->store()

In reply to Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/adc/pac1934.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/iio/adc/pac1934.c +6 -3
index 23055405a6e0..2d934452eb11 100644
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
+#include <linux/kstrtox.h>
 #include <linux/unaligned.h>
 
 /*
@@ -494,11 +495,13 @@ static ssize_t pac1934_shunt_value_store(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct pac1934_chip_info *info = iio_priv(indio_dev);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int sh_val;
+	unsigned int sh_val;
+	int ret;
 
-	if (kstrtouint(buf, 10, &sh_val)) {
+	ret = kstrtouint(buf, 10, &sh_val);
+	if (ret) {
 		dev_err(dev, "Shunt value is not valid\n");
-		return -EINVAL;
+		return ret;
 	}
 
 	scoped_guard(mutex, &info->lock)
Signature · 1 line
2.50.1
maintainer Reviewed-by on v1 4/4
#18 lore raw

Re: [PATCH v1 4/4] iio: adc: pac1934: Unshadow error codes in ->store()

Quoted 43 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/adc/pac1934.c | 9 ++++++---

 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/iio/adc/pac1934.c +6 -3
index 23055405a6e0..2d934452eb11 100644
@@ -19,6 +19,7 @@
  #include <linux/i2c.h>
  #include <linux/iio/iio.h>
  #include <linux/iio/sysfs.h>
+#include <linux/kstrtox.h>
  #include <linux/unaligned.h>
 
  /*
@@ -494,11 +495,13 @@ static ssize_t pac1934_shunt_value_store(struct
 device *dev,
         struct iio_dev *indio_dev = dev_to_iio_dev(dev);
         struct pac1934_chip_info *info = iio_priv(indio_dev);
         struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-       int sh_val;
+       unsigned int sh_val;
+       int ret;
 
-       if (kstrtouint(buf, 10, &sh_val)) {
+       ret = kstrtouint(buf, 10, &sh_val);
+       if (ret) {
                 dev_err(dev, "Shunt value is not valid\n");
-               return -EINVAL;
+               return ret;
         }
 
Quoted 3 lines

        scoped_guard(mutex, &info->lock)
--
2.50.1

Reviewed-by on v1 4/4
#19 lore raw

Re: [PATCH v1 4/4] iio: adc: pac1934: Unshadow error codes in ->store()

In reply to Andy Shevchenko
Quoted 11 lines · CDT Andy Shevchenko

kstrtox() may return different error codes.

Unshadow them in the ->store() callback to give better error report.

While at it, add missing kstrtox.h inclusion.

---
 drivers/iio/adc/pac1934.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

thanks,
max

maintainer Applied
#20 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · On Thu, 13 Aug 2026 09:16:49 +0200 Andy Shevchenko…

kstrtox() may return different error codes. Allow them to be returned. This mini-series makes all IIO drivers to follow the same pattern when using kstrtox() APIs. Patches can be individually applied, the series is just a union by the subject, no code dependencies are there.

Andy Shevchenko (4):
iio: light: Unshadow error codes in ->store()
iio: imu: inv_mpu6050: Unshadow error codes in ->store()
iio: chemical: sps30: Unshadow error codes in ->store()
iio: adc: pac1934: Unshadow error codes in ->store()

Applied. thanks

Jonathan

Quoted 10 lines
 drivers/iio/adc/pac1934.c                  |  9 ++++++---
 drivers/iio/chemical/sps30.c               | 11 ++++++++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  6 ++++--
 drivers/iio/light/isl29018.c               |  7 +++++--
 drivers/iio/light/lm3533-als.c             | 11 +++++++----
 drivers/iio/light/tsl2583.c                | 15 +++++++++++----
 drivers/iio/light/tsl2772.c                | 16 ++++++++++++----
 7 files changed, 53 insertions(+), 22 deletions(-)