* [PATCH] iio: accel: sca3000: fix frequency divider condition check
@ 2026-08-19 11:41 Salah Triki
2026-08-19 11:51 ` Joshua Crofts
2026-08-19 13:38 ` Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Salah Triki @ 2026-08-19 11:41 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Salah Triki
When setting the sampling frequency, the check for `base_freq / 2` is
followed by an independent `if` statement for `base_freq / 4`. If `val`
equals `base_freq / 2`, the second check fails and falls through to the
`else if (val != base_freq)` branch, returning `-EINVAL` erroneously.
Fix this by chaining the checks with `else if`.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/iio/accel/sca3000.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index 573831199bba..cced5cd82b02 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -638,7 +638,7 @@ static int sca3000_write_raw_samp_freq(struct sca3000_state *st, int val)
if (val == base_freq / 2)
ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_2;
- if (val == base_freq / 4)
+ else if (val == base_freq / 4)
ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_4;
else if (val != base_freq)
return -EINVAL;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: accel: sca3000: fix frequency divider condition check
2026-08-19 11:41 [PATCH] iio: accel: sca3000: fix frequency divider condition check Salah Triki
@ 2026-08-19 11:51 ` Joshua Crofts
2026-08-23 0:48 ` Jonathan Cameron
2026-08-19 13:38 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Joshua Crofts @ 2026-08-19 11:51 UTC (permalink / raw)
To: Salah Triki
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Wed, 19 Aug 2026 12:41:01 +0100
Salah Triki <salah.triki@gmail.com> wrote:
> When setting the sampling frequency, the check for `base_freq / 2` is
> followed by an independent `if` statement for `base_freq / 4`. If `val`
> equals `base_freq / 2`, the second check fails and falls through to the
> `else if (val != base_freq)` branch, returning `-EINVAL` erroneously.
>
> Fix this by chaining the checks with `else if`.
>
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
Good catch, this issue is 10 years old!
However, you're missing a fixes tag, I think b4 will pick it up
if I leave it here since I already ran git blame.
Fixes: e0f3fc9b47e6 ("iio: accel: sca3000_core: implemented IIO_CHAN_INFO_SAMP_FREQ")
+ cc stable
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: accel: sca3000: fix frequency divider condition check
2026-08-19 11:41 [PATCH] iio: accel: sca3000: fix frequency divider condition check Salah Triki
2026-08-19 11:51 ` Joshua Crofts
@ 2026-08-19 13:38 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-08-19 13:38 UTC (permalink / raw)
To: Salah Triki
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Wed, Aug 19, 2026 at 12:41:01PM +0100, Salah Triki wrote:
> When setting the sampling frequency, the check for `base_freq / 2` is
> followed by an independent `if` statement for `base_freq / 4`. If `val`
> equals `base_freq / 2`, the second check fails and falls through to the
> `else if (val != base_freq)` branch, returning `-EINVAL` erroneously.
>
> Fix this by chaining the checks with `else if`.
This needs a Fixes tag.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: accel: sca3000: fix frequency divider condition check
2026-08-19 11:51 ` Joshua Crofts
@ 2026-08-23 0:48 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-08-23 0:48 UTC (permalink / raw)
To: Joshua Crofts
Cc: Salah Triki, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Wed, 19 Aug 2026 13:51:56 +0200
Joshua Crofts <joshua.crofts1@gmail.com> wrote:
> On Wed, 19 Aug 2026 12:41:01 +0100
> Salah Triki <salah.triki@gmail.com> wrote:
>
> > When setting the sampling frequency, the check for `base_freq / 2` is
> > followed by an independent `if` statement for `base_freq / 4`. If `val`
> > equals `base_freq / 2`, the second check fails and falls through to the
> > `else if (val != base_freq)` branch, returning `-EINVAL` erroneously.
> >
> > Fix this by chaining the checks with `else if`.
> >
> > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> > ---
>
> Good catch, this issue is 10 years old!
>
> However, you're missing a fixes tag, I think b4 will pick it up
> if I leave it here since I already ran git blame.
>
> Fixes: e0f3fc9b47e6 ("iio: accel: sca3000_core: implemented IIO_CHAN_INFO_SAMP_FREQ")
Thanks - b4 indeed picks it up. It saves me time even though b4 puts it
in the wrong place (well the right place given it came from the thread, but
wrong as it should have been there in the first place).
>
> + cc stable
>
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-23 0:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19 11:41 [PATCH] iio: accel: sca3000: fix frequency divider condition check Salah Triki
2026-08-19 11:51 ` Joshua Crofts
2026-08-23 0:48 ` Jonathan Cameron
2026-08-19 13:38 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox