staging: iio: adc: ad7816: use sysfs_streq() instead of strcmp()
Subsystems (4)
PATCH 1/1 staging: iio: adc: ad7816: use sysfs_streq() instead of strcmp()
Use sysfs_streq() to compare the input buffer with the mode strings. This is more robust as it ignores trailing newlines, making it safer for sysfs store functions.
--- drivers/staging/iio/adc/ad7816.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7816.c +1 -1
@@ -136,7 +136,7 @@ static ssize_t ad7816_store_mode(struct device *dev,struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad7816_chip_info *chip =iio_priv (indio_dev); -if (strcmp (buf,"full" ) ==0 ) { +if (sysfs_streq (buf,"full" )) {gpiod_set_value (chip->rdwr_pin,1 ); chip->mode =AD7816_FULL ; }else {
Signature · 1 line
2.34.1
Quoted 3 lines · Md. Mahmudul Hasan Mabud
Use
sysfs_streq()to compare the input buffer with the mode strings. This is more robust as it ignores trailing newlines, making it safer for sysfs store functions.
...
drivers/staging/iio/adc/ad7816.c static ssize_t ad7816_store_mode(struct device *dev, · line 141
Quoted 7 lines
drivers/staging/iio/adc/ad7816.c +1
-1struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad7816_chip_info *chip =iio_priv (indio_dev); -if (strcmp (buf,"full" ) ==0 ) { +if (sysfs_streq (buf,"full" )) {gpiod_set_value (chip->rdwr_pin,1 ); chip->mode =AD7816_FULL ;
I think it might be better to do more work on this. First of all, convert to use IIO_DEVICE_ATTR_RW(). Second, convert to use sysfs_emit() instead of sprintf(). But with that, switch to use a static array
static const char * const modes[] = {
[_FULL] = "full";
[_PD] = "power-save";
};This will need redefinition to start from 0 (I don't see why it needs to start from 1).
#define _FULL 0
#define _PD 1
This allows to switch to sysfs_match_string() and return an error on unrecognized input (which is absent right now).
So, something like series out of ~3-4 patches is expected.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 28 lines · On Mon, 30 Mar 2026 13:09:20 +0300 Andy Shevchenko…
Quoted 3 lines · Md. Mahmudul Hasan Mabud
Use
sysfs_streq()to compare the input buffer with the mode strings. This is more robust as it ignores trailing newlines, making it safer for sysfs store functions....
drivers/staging/iio/adc/ad7816.c static ssize_t ad7816_store_mode(struct device *dev, · line 141
Quoted 7 lines
drivers/staging/iio/adc/ad7816.c +1
-1struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad7816_chip_info *chip =iio_priv (indio_dev); -if (strcmp (buf,"full" ) ==0 ) { +if (sysfs_streq (buf,"full" )) {gpiod_set_value (chip->rdwr_pin,1 ); chip->mode =AD7816_FULL ;I think it might be better to do more work on this. First of all, convert to use
IIO_DEVICE_ATTR_RW(). Second, convert to usesysfs_emit()instead ofsprintf(). But with that, switch to use a static arraystatic const char * const modes[] = { [_FULL] = "full"; [_PD] = "power-save"; };This will need redefinition to start from 0 (I don't see why it needs to start from 1).
Quoted 8 lines
#define
_FULL0
#define_PD1This allows to switch to
sysfs_match_string()and return an error on unrecognized input (which is absent right now).So, something like series out of ~3-4 patches is expected.
Hmm. ok I guess to cleaning this up, but worth noting that this bit of ABI is custom and very very likely to go away in the longer term if this driver is cleaned up enough to move out of staging,
Jonathan