[PATCH v3 2/4] staging: iio: adc: ad7816: use sysfs_match_string() for mode selection

Md. Mahmudul Hasan Mabud
2026-03-30T18:17:50Z

Replace manual strcmp() logic with sysfs_match_string() to simplify
the mode selection process. This reduces boilerplate code and
leverages standard kernel helper functions for string matching.

Signed-off-by: Md. Mahmudul Hasan Mabud <mdmahmudulhasan1511@gmail.com>
---
drivers/staging/iio/adc/ad7816.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 5acfceb90..f9a0a5a69 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -58,6 +58,11 @@ enum ad7816_type {
ID_AD7818,
};

+static const char * const ad7816_modes[] = {
+ [AD7816_FULL] = "full",
+ [AD7816_PD] = "power-save",
+};
+
/*
* ad7816 data access by SPI
*/
@@ -135,14 +140,14 @@ 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);
+ int ret;

- if (strcmp(buf, "full") == 0) {
- gpiod_set_value(chip->rdwr_pin, 1);
- chip->mode = AD7816_FULL;
- } else {
- gpiod_set_value(chip->rdwr_pin, 0);
- chip->mode = AD7816_PD;
- }
+ ret = sysfs_match_string(ad7816_modes, buf);
+ if (ret < 0)
+ return ret;
+
+ chip->mode = ret;
+ gpiod_set_value(chip->rdwr_pin, ret == AD7816_FULL);

return len;
}
--
2.34.1