drivers/staging/iio/adc/ad7816.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The mode setting logic in ad7816_store_mode was reversed due to
incorrect handling of the strcmp return value. strcmp returns 0 on
match, so the `if (strcmp(buf, "full"))` block executed when the
input was not "full".
This resulted in "full" setting the mode to AD7816_PD (power-down) and
other inputs setting it to AD7816_FULL.
Fix this by checking it against 0 to correctly check for "full" and
"power-down", mapping them to AD7816_FULL and AD7816_PD respectively.
Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
Cc: stable@vger.kernel.org
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
Changes since v3:
- Tag stable@vger.kernel.org instead of an email CC
- Use the correct version for patch
Changes since v2:
- Add fixes tag that references commit that introduced the bug.
- Replace sysfs_streq with strcmp.
---
drivers/staging/iio/adc/ad7816.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 6c14d7bcdd675..081b17f498638 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -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")) {
+ if (strcmp(buf, "full") == 0) {
gpiod_set_value(chip->rdwr_pin, 1);
chip->mode = AD7816_FULL;
} else {
--
2.43.0
On Mon, 2025-04-14 at 11:40 -0400, Gabriel Shahrouzi wrote:
> The mode setting logic in ad7816_store_mode was reversed due to
> incorrect handling of the strcmp return value. strcmp returns 0 on
> match, so the `if (strcmp(buf, "full"))` block executed when the
> input was not "full".
>
> This resulted in "full" setting the mode to AD7816_PD (power-down) and
> other inputs setting it to AD7816_FULL.
>
> Fix this by checking it against 0 to correctly check for "full" and
> "power-down", mapping them to AD7816_FULL and AD7816_PD respectively.
>
> Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> ---
LGTM, do you happen to have this device? It would more interesting to move this
driver out of staging :)
Acked-by: Nuno Sá <nuno.sa@analog.com>
> Changes since v3:
> - Tag stable@vger.kernel.org instead of an email CC
> - Use the correct version for patch
> Changes since v2:
> - Add fixes tag that references commit that introduced the bug.
> - Replace sysfs_streq with strcmp.
> ---
> drivers/staging/iio/adc/ad7816.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/adc/ad7816.c
> b/drivers/staging/iio/adc/ad7816.c
> index 6c14d7bcdd675..081b17f498638 100644
> --- a/drivers/staging/iio/adc/ad7816.c
> +++ b/drivers/staging/iio/adc/ad7816.c
> @@ -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")) {
> + if (strcmp(buf, "full") == 0) {
> gpiod_set_value(chip->rdwr_pin, 1);
> chip->mode = AD7816_FULL;
> } else {
On Tue, Apr 15, 2025 at 5:13 AM Nuno Sá <noname.nuno@gmail.com> wrote:
>
> On Mon, 2025-04-14 at 11:40 -0400, Gabriel Shahrouzi wrote:
> > The mode setting logic in ad7816_store_mode was reversed due to
> > incorrect handling of the strcmp return value. strcmp returns 0 on
> > match, so the `if (strcmp(buf, "full"))` block executed when the
> > input was not "full".
> >
> > This resulted in "full" setting the mode to AD7816_PD (power-down) and
> > other inputs setting it to AD7816_FULL.
> >
> > Fix this by checking it against 0 to correctly check for "full" and
> > "power-down", mapping them to AD7816_FULL and AD7816_PD respectively.
> >
> > Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> > ---
>
> LGTM, do you happen to have this device? It would more interesting to move this
> driver out of staging :)
Unfortunately, I do not have this device. However, I would still be
interested in contributing if possible. I was looking over
https://lore.kernel.org/all/20230716144024.30ded663@jic23-huawei/T/
where the goal seemed to be to modernize it by replacing the sysfs
interface with the iio channel. I also looked through the datasheet
and it seemed to be missing some stuff like a channel that can be
selected.
>
> Acked-by: Nuno Sá <nuno.sa@analog.com>
>
> > Changes since v3:
> > - Tag stable@vger.kernel.org instead of an email CC
> > - Use the correct version for patch
> > Changes since v2:
> > - Add fixes tag that references commit that introduced the bug.
> > - Replace sysfs_streq with strcmp.
> > ---
> > drivers/staging/iio/adc/ad7816.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/iio/adc/ad7816.c
> > b/drivers/staging/iio/adc/ad7816.c
> > index 6c14d7bcdd675..081b17f498638 100644
> > --- a/drivers/staging/iio/adc/ad7816.c
> > +++ b/drivers/staging/iio/adc/ad7816.c
> > @@ -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")) {
> > + if (strcmp(buf, "full") == 0) {
> > gpiod_set_value(chip->rdwr_pin, 1);
> > chip->mode = AD7816_FULL;
> > } else {
On Tue, 15 Apr 2025 09:54:00 -0400
Gabriel Shahrouzi <gshahrouzi@gmail.com> wrote:
> On Tue, Apr 15, 2025 at 5:13 AM Nuno Sá <noname.nuno@gmail.com> wrote:
> >
> > On Mon, 2025-04-14 at 11:40 -0400, Gabriel Shahrouzi wrote:
> > > The mode setting logic in ad7816_store_mode was reversed due to
> > > incorrect handling of the strcmp return value. strcmp returns 0 on
> > > match, so the `if (strcmp(buf, "full"))` block executed when the
> > > input was not "full".
> > >
> > > This resulted in "full" setting the mode to AD7816_PD (power-down) and
> > > other inputs setting it to AD7816_FULL.
> > >
> > > Fix this by checking it against 0 to correctly check for "full" and
> > > "power-down", mapping them to AD7816_FULL and AD7816_PD respectively.
> > >
> > > Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> > > ---
> >
> > LGTM, do you happen to have this device? It would more interesting to move this
> > driver out of staging :)
> Unfortunately, I do not have this device. However, I would still be
> interested in contributing if possible. I was looking over
> https://lore.kernel.org/all/20230716144024.30ded663@jic23-huawei/T/
> where the goal seemed to be to modernize it by replacing the sysfs
> interface with the iio channel. I also looked through the datasheet
> and it seemed to be missing some stuff like a channel that can be
> selected.
> >
> > Acked-by: Nuno Sá <nuno.sa@analog.com>
Applied to the fixes-togreg branch of iio.git but amended the patch title
to start wit
staging: iio: adc: ad7816:
so people looking at a short log can see what it is touching.
Thanks,
Jonathan
> >
> > > Changes since v3:
> > > - Tag stable@vger.kernel.org instead of an email CC
> > > - Use the correct version for patch
> > > Changes since v2:
> > > - Add fixes tag that references commit that introduced the bug.
> > > - Replace sysfs_streq with strcmp.
> > > ---
> > > drivers/staging/iio/adc/ad7816.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/iio/adc/ad7816.c
> > > b/drivers/staging/iio/adc/ad7816.c
> > > index 6c14d7bcdd675..081b17f498638 100644
> > > --- a/drivers/staging/iio/adc/ad7816.c
> > > +++ b/drivers/staging/iio/adc/ad7816.c
> > > @@ -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")) {
> > > + if (strcmp(buf, "full") == 0) {
> > > gpiod_set_value(chip->rdwr_pin, 1);
> > > chip->mode = AD7816_FULL;
> > > } else {
>
On Fri, Apr 18, 2025 at 11:18 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 15 Apr 2025 09:54:00 -0400
> Gabriel Shahrouzi <gshahrouzi@gmail.com> wrote:
>
> > On Tue, Apr 15, 2025 at 5:13 AM Nuno Sá <noname.nuno@gmail.com> wrote:
> > >
> > > On Mon, 2025-04-14 at 11:40 -0400, Gabriel Shahrouzi wrote:
> > > > The mode setting logic in ad7816_store_mode was reversed due to
> > > > incorrect handling of the strcmp return value. strcmp returns 0 on
> > > > match, so the `if (strcmp(buf, "full"))` block executed when the
> > > > input was not "full".
> > > >
> > > > This resulted in "full" setting the mode to AD7816_PD (power-down) and
> > > > other inputs setting it to AD7816_FULL.
> > > >
> > > > Fix this by checking it against 0 to correctly check for "full" and
> > > > "power-down", mapping them to AD7816_FULL and AD7816_PD respectively.
> > > >
> > > > Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> > > > Cc: stable@vger.kernel.org
> > > > Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> > > > ---
> > >
> > > LGTM, do you happen to have this device? It would more interesting to move this
> > > driver out of staging :)
> > Unfortunately, I do not have this device. However, I would still be
> > interested in contributing if possible. I was looking over
> > https://lore.kernel.org/all/20230716144024.30ded663@jic23-huawei/T/
> > where the goal seemed to be to modernize it by replacing the sysfs
> > interface with the iio channel. I also looked through the datasheet
> > and it seemed to be missing some stuff like a channel that can be
> > selected.
> > >
> > > Acked-by: Nuno Sá <nuno.sa@analog.com>
> Applied to the fixes-togreg branch of iio.git but amended the patch title
> to start wit
> staging: iio: adc: ad7816:
>
> so people looking at a short log can see what it is touching.
That makes sense — it's clearer for anyone skimming the short log to
see what it's touching. Appreciate the correction.
>
> Thanks,
>
> Jonathan
>
> > >
> > > > Changes since v3:
> > > > - Tag stable@vger.kernel.org instead of an email CC
> > > > - Use the correct version for patch
> > > > Changes since v2:
> > > > - Add fixes tag that references commit that introduced the bug.
> > > > - Replace sysfs_streq with strcmp.
> > > > ---
> > > > drivers/staging/iio/adc/ad7816.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/staging/iio/adc/ad7816.c
> > > > b/drivers/staging/iio/adc/ad7816.c
> > > > index 6c14d7bcdd675..081b17f498638 100644
> > > > --- a/drivers/staging/iio/adc/ad7816.c
> > > > +++ b/drivers/staging/iio/adc/ad7816.c
> > > > @@ -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")) {
> > > > + if (strcmp(buf, "full") == 0) {
> > > > gpiod_set_value(chip->rdwr_pin, 1);
> > > > chip->mode = AD7816_FULL;
> > > > } else {
> >
>
© 2016 - 2025 Red Hat, Inc.