iio: accel: sca3000: fix frequency divider condition check
PATCH v2 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.
---
Changes since v1:
- Add Fixes and Reviewed-by tags
drivers/iio/accel/sca3000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/sca3000.c +1 -1
@@ -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
Jonathan Cameron
maintainerQuoted 11 lines · On Fri, 21 Aug 2026 16:01:12 +0100 Salah Triki <[email protected]> wrote:
When setting the sampling frequency, the check for
base_freq / 2is followed by an independentifstatement forbase_freq / 4. Ifvalequalsbase_freq / 2, the second check fails and falls through to theelse if (val != base_freq)branch, returning-EINVALerroneously.Fix this by chaining the checks with
else if.Fixes e0f3fc9b47e6 ("iio: accel: sca3000_core: implemented IIO_CHAN_INFO_SAMP_FREQ")Signed-off-by Salah Triki <[email protected]>Reviewed-by Joshua Crofts <[email protected]>---
Ah, I should have checked for a new version. Generally when it's just tags pick up (even for fixes) no need to send a new version. Never mind though as I think the right thing landed anyway!
Jonathan
Quoted 19 lines
Changes since v1:
- Add Fixes and Reviewed-by tagsdrivers/iio/accel/sca3000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/accel/sca3000.c +1
-1@@ -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 ;