* [PATCH] iio: adc: Correct conditional logic for store mode
@ 2025-04-14 14:09 Gabriel Shahrouzi
2025-04-14 14:59 ` David Lechner
0 siblings, 1 reply; 6+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-14 14:09 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Greg Kroah-Hartman, linux-iio, linux-staging, linux-kernel
Cc: gshahrozui, skhan, kernelmentees, Gabriel Shahrouzi
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.
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
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..6b545547660dd 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 (sysfs_streq(buf, "full")) {
gpiod_set_value(chip->rdwr_pin, 1);
chip->mode = AD7816_FULL;
} else {
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: Correct conditional logic for store mode
2025-04-14 14:09 [PATCH] iio: adc: Correct conditional logic for store mode Gabriel Shahrouzi
@ 2025-04-14 14:59 ` David Lechner
2025-04-14 15:02 ` David Lechner
0 siblings, 1 reply; 6+ messages in thread
From: David Lechner @ 2025-04-14 14:59 UTC (permalink / raw)
To: Gabriel Shahrouzi, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Greg Kroah-Hartman, linux-iio, linux-staging,
linux-kernel
Cc: gshahrozui, skhan, kernelmentees
On 4/14/25 9:09 AM, 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.
>
Sounds like we need a Fixes: tag here that reference the commit
that introduced the bug.
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> ---
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: Correct conditional logic for store mode
2025-04-14 14:59 ` David Lechner
@ 2025-04-14 15:02 ` David Lechner
2025-04-14 15:35 ` Gabriel Shahrouzi
0 siblings, 1 reply; 6+ messages in thread
From: David Lechner @ 2025-04-14 15:02 UTC (permalink / raw)
To: Gabriel Shahrouzi, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Greg Kroah-Hartman, linux-iio, linux-staging,
linux-kernel
Cc: gshahrozui, skhan, kernelmentees
On 4/14/25 9:59 AM, David Lechner wrote:
> On 4/14/25 9:09 AM, 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.
>>
>
> Sounds like we need a Fixes: tag here that reference the commit
> that introduced the bug.
>
>> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
>> ---
There is also a typo in your email address in the cc: gshahrozui@gmail.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] iio: adc: Correct conditional logic for store mode
@ 2025-04-14 15:29 Gabriel Shahrouzi
0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-14 15:29 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Greg Kroah-Hartman, linux-iio, linux-staging, linux-kernel
Cc: gshahrouzi, skhan, kernelmentees, stable
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")
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: Correct conditional logic for store mode
2025-04-14 15:02 ` David Lechner
@ 2025-04-14 15:35 ` Gabriel Shahrouzi
0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-14 15:35 UTC (permalink / raw)
To: David Lechner
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Greg Kroah-Hartman, linux-iio, linux-staging, linux-kernel,
gshahrozui, skhan, kernelmentees
On Mon, Apr 14, 2025 at 11:02 AM David Lechner <dlechner@baylibre.com> wrote:
>
> On 4/14/25 9:59 AM, David Lechner wrote:
> > On 4/14/25 9:09 AM, 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.
> >>
> >
> > Sounds like we need a Fixes: tag here that reference the commit
> > that introduced the bug.
Sounds good. Included the fixes tag and CC'd stable@vger.kernel.org.
> >
> >> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> >> ---
>
> There is also a typo in your email address in the cc: gshahrozui@gmail.com
Whoops - I'll update that.
I just realized I didn't update the version for the second patch
correctly so I'll send in a new one.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] iio: adc: Correct conditional logic for store mode
@ 2025-04-14 15:39 Gabriel Shahrouzi
0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-14 15:39 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Greg Kroah-Hartman, linux-iio, linux-staging, linux-kernel
Cc: gshahrouzi, skhan, kernelmentees
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")
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-14 15:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 14:09 [PATCH] iio: adc: Correct conditional logic for store mode Gabriel Shahrouzi
2025-04-14 14:59 ` David Lechner
2025-04-14 15:02 ` David Lechner
2025-04-14 15:35 ` Gabriel Shahrouzi
-- strict thread matches above, loose matches on Subject: below --
2025-04-14 15:29 Gabriel Shahrouzi
2025-04-14 15:39 Gabriel Shahrouzi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox