Skip to contentSkip to conversation

iio: accel: sca3000: fix frequency divider condition check

PATCH Applied Salah Triki 4 participants 4 messages Aug 19 – Aug 23 IIO

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: sca3000: fix frequency divider condition check

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.

---
 drivers/iio/accel/sca3000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/sca3000.c +1 -1
index 573831199bba..cced5cd82b02 100644
@@ -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;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Wed, 19 Aug 2026 12:41:01 +0100 Salah Triki <[email protected]> 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.

---

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

Signature · 2 lines
Kind regards,
Joshua Crofts
maintainer Applied
#2 lore raw
Quoted 13 lines · On Wed, 19 Aug 2026 13:51:56 +0200 Joshua Crofts <[email protected]>…
Quoted 9 lines · On Wed, 19 Aug 2026 12:41:01 +0100 Salah Triki <[email protected]> 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.

---

Quoted 6 lines

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).

Quoted 4 lines

+ cc stable

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 1 line
#3 lore raw
In reply to Salah Triki
Quoted 6 lines · 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.

This needs a Fixes tag.

Signature · 2 lines
With Best Regards,
Andy Shevchenko