* [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing
@ 2026-10-14 9:11 Abdelnasser Hussein
2026-10-17 22:17 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Abdelnasser Hussein @ 2026-10-14 9:11 UTC (permalink / raw)
To: jic23
Cc: gregkh, dlechner, nuno.sa, andy, u.kleine-koenig, joshua.crofts1,
linux-iio, linux-staging, linux-kernel, Abdelnasser Hussein
Replace manual character checks (e.g., buf[0] == '1') with the standard
kstrtobool() API in sysfs store functions.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
---
Changes in v3:
- Change _adt7316_store_enabled() parameter type from int to bool to match callers (Andy Shevchenko).
- Update adt7316_disable() and adt7316_enable() to pass false/true instead of 0/1 (Andy Shevchenko).
Changes in v2:
- Include <linux/kstrtox.h>.
- Rename the boolean variable from 'req' to 'val' for clarity.
- Add Reviewed-by tag from Joshua Crofts.
drivers/staging/iio/addac/adt7316.c | 101 ++++++++++++++++++++++------
1 file changed, 81 insertions(+), 20 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index 20f6052cc7fb..ec1c33ad5ace 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -17,6 +17,7 @@
#include <linux/i2c.h>
#include <linux/rtc.h>
#include <linux/module.h>
+#include <linux/kstrtox.h>
#include <linux/iio/iio.h>
#include <linux/iio/events.h>
@@ -220,7 +221,7 @@ static ssize_t adt7316_show_enabled(struct device *dev,
}
static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
- int enable)
+ bool enable)
{
u8 config1;
int ret;
@@ -246,12 +247,12 @@ static ssize_t adt7316_store_enabled(struct device *dev,
{
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- int enable;
+ bool enable;
+ int ret;
- if (buf[0] == '1')
- enable = 1;
- else
- enable = 0;
+ ret = kstrtobool(buf, &enable);
+ if (ret)
+ return ret;
if (_adt7316_store_enabled(chip, enable) < 0)
return -EIO;
@@ -285,13 +286,18 @@ static ssize_t adt7316_store_select_ex_temp(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config1;
+ bool val;
int ret;
if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
return -EPERM;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config1 = chip->config1 & (~ADT7516_SEL_EX_TEMP);
- if (buf[0] == '1')
+ if (val)
config1 |= ADT7516_SEL_EX_TEMP;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
@@ -482,10 +488,15 @@ static ssize_t adt7316_store_disable_averaging(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config2;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config2 = chip->config2 & (~ADT7316_DISABLE_AVERAGING);
- if (buf[0] == '1')
+ if (val)
config2 |= ADT7316_DISABLE_AVERAGING;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
@@ -521,10 +532,15 @@ static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config2;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config2 = chip->config2 & (~ADT7316_EN_SMBUS_TIMEOUT);
- if (buf[0] == '1')
+ if (val)
config2 |= ADT7316_EN_SMBUS_TIMEOUT;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
@@ -559,10 +575,15 @@ static ssize_t adt7316_store_powerdown(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config1;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config1 = chip->config1 & (~ADT7316_PD);
- if (buf[0] == '1')
+ if (val)
config1 |= ADT7316_PD;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
@@ -597,10 +618,15 @@ static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config3;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config3 = chip->config3 & (~ADT7316_ADCLK_22_5);
- if (buf[0] == '1')
+ if (val)
config3 |= ADT7316_ADCLK_22_5;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
@@ -640,13 +666,18 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config3;
+ bool val;
int ret;
if (chip->id == ID_ADT7318 || chip->id == ID_ADT7519)
return -EPERM;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION);
- if (buf[0] == '1')
+ if (val)
config3 |= ADT7316_DA_HIGH_RESOLUTION;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
@@ -685,12 +716,17 @@ static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config3;
+ bool val;
int ret;
if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
return -EPERM;
- if (buf[0] != '1')
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
+ if (!val)
config3 = chip->config3 & (~ADT7516_AIN_IN_VREF);
else
config3 = chip->config3 | ADT7516_AIN_IN_VREF;
@@ -728,10 +764,15 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config3;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config3 = chip->config3 & (~ADT7316_EN_IN_TEMP_PROP_DACA);
- if (buf[0] == '1')
+ if (val)
config3 |= ADT7316_EN_IN_TEMP_PROP_DACA;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
@@ -767,10 +808,15 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config3;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config3 = chip->config3 & (~ADT7316_EN_EX_TEMP_PROP_DACB);
- if (buf[0] == '1')
+ if (val)
config3 |= ADT7316_EN_EX_TEMP_PROP_DACB;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
@@ -967,10 +1013,15 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 dac_config;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_AB);
- if (buf[0] == '1')
+ if (val)
dac_config |= ADT7316_VREF_BYPASS_DAC_AB;
ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
@@ -1006,10 +1057,15 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 dac_config;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_CD);
- if (buf[0] == '1')
+ if (val)
dac_config |= ADT7316_VREF_BYPASS_DAC_CD;
ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
@@ -1969,10 +2025,15 @@ static ssize_t adt7316_set_int_enabled(struct device *dev,
struct iio_dev *dev_info = dev_to_iio_dev(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
u8 config1;
+ bool val;
int ret;
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
config1 = chip->config1 & (~ADT7316_INT_EN);
- if (buf[0] == '1')
+ if (val)
config1 |= ADT7316_INT_EN;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
@@ -2084,7 +2145,7 @@ static int adt7316_disable(struct device *dev)
struct iio_dev *dev_info = dev_get_drvdata(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- return _adt7316_store_enabled(chip, 0);
+ return _adt7316_store_enabled(chip, false);
}
static int adt7316_enable(struct device *dev)
@@ -2092,7 +2153,7 @@ static int adt7316_enable(struct device *dev)
struct iio_dev *dev_info = dev_get_drvdata(dev);
struct adt7316_chip_info *chip = iio_priv(dev_info);
- return _adt7316_store_enabled(chip, 1);
+ return _adt7316_store_enabled(chip, true);
}
EXPORT_GPL_SIMPLE_DEV_PM_OPS(adt7316_pm_ops, adt7316_disable, adt7316_enable);
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing
2026-10-14 9:11 [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing Abdelnasser Hussein
@ 2026-10-17 22:17 ` Jonathan Cameron
2026-10-18 6:22 ` Abdelnasser Hussein
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2026-10-17 22:17 UTC (permalink / raw)
To: Abdelnasser Hussein
Cc: gregkh, dlechner, nuno.sa, andy, u.kleine-koenig, joshua.crofts1,
linux-iio, linux-staging, linux-kernel
On Wed, 14 Oct 2026 12:11:11 +0300
Abdelnasser Hussein <abdelnasserhussein11@gmail.com> wrote:
> Replace manual character checks (e.g., buf[0] == '1') with the standard
> kstrtobool() API in sysfs store functions.
>
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
Work on this driver always feels like we are dancing around a complete
mess. The thing needs radical modifications so most likely changes
like this are to code that will go away.
Still that doesn't mean small changes aren't going to help whoever
does that work read the driver more easily.
This looks fine to me, but given the potential issue with Josh's tag
I'll leave it until that is addressed. Perhaps I just missed an email!
Jonathan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing
2026-10-17 22:17 ` Jonathan Cameron
@ 2026-10-18 6:22 ` Abdelnasser Hussein
2026-10-19 3:08 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Abdelnasser Hussein @ 2026-10-18 6:22 UTC (permalink / raw)
To: Jonathan Cameron
Cc: gregkh, dlechner, nuno.sa, andy, u.kleine-koenig, joshua.crofts1,
linux-iio, linux-staging, linux-kernel
Hi Jonathan,
Thank you for your feedback.
I apologize for the confusion regarding Joshua's tag. When Joshua
reviewed v1, he pointed out the necessary fixes and concluded with
"Otherwise LGTM." Therefore, I mistakenly assumed that I was required
to add a "Reviewed-by" tag for him in the next version to acknowledge
his review.
Thank you for clarifying this for me, and I hope it didn't cause too
much extra noise.
I also really appreciate your encouraging words about these small cleanups.
Best regards, Abdelnasser
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing
2026-10-18 6:22 ` Abdelnasser Hussein
@ 2026-10-19 3:08 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-10-19 3:08 UTC (permalink / raw)
To: Abdelnasser Hussein
Cc: gregkh, dlechner, nuno.sa, andy, u.kleine-koenig, joshua.crofts1,
linux-iio, linux-staging, linux-kernel
On Sun, 18 Oct 2026 09:22:35 +0300
Abdelnasser Hussein <abdelnasserhussein11@gmail.com> wrote:
> Hi Jonathan,
>
> Thank you for your feedback.
>
> I apologize for the confusion regarding Joshua's tag. When Joshua
> reviewed v1, he pointed out the necessary fixes and concluded with
> "Otherwise LGTM." Therefore, I mistakenly assumed that I was required
> to add a "Reviewed-by" tag for him in the next version to acknowledge
> his review.
>
> Thank you for clarifying this for me, and I hope it didn't cause too
> much extra noise.
>
> I also really appreciate your encouraging words about these small cleanups.
>
> Best regards, Abdelnasser
Applied with Josh's tag dropped.
Thanks
Jonathan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-19 3:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 9:11 [PATCH v3] staging: iio: adt7316: use kstrtobool() for sysfs boolean parsing Abdelnasser Hussein
2026-10-17 22:17 ` Jonathan Cameron
2026-10-18 6:22 ` Abdelnasser Hussein
2026-10-19 3:08 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®