[PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio
From: Rupesh Majhi
Date: Thu Oct 29 2026 - 18:08:01 EST
The rate and ratio setters accept 0, which also covers 0.5. ilog2(0)
gives -1, which masked into the register is 128 Hz or the reserved
precision 0b1111. The latter makes every pressure read fail with
-ERANGE and temperature read 974 degrees C.
Reject values below 1.
Fixes: ba6ec48e76bc ("iio: Add driver for Infineon DPS310")
Fixes: d711a3c7dc82 ("iio: dps310: Add pressure sensing capability")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com
Signed-off-by: Rupesh Majhi <zoone.rupert@xxxxxxxxx>
---
Cc: Paulius Zaleckas <paulius.zaleckas@xxxxxxxxx>
drivers/iio/pressure/dps310.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 71053f4463e5..b6aa5dbe2bcd 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -410,7 +410,7 @@ static int dps310_set_pres_precision(struct dps310_data *data, int val)
int rc;
u8 shift_en;
- if (val < 0 || val > 128)
+ if (val < 1 || val > 128)
return -EINVAL;
shift_en = val >= 16 ? DPS310_PRS_SHIFT_EN : 0;
@@ -433,7 +433,7 @@ static int dps310_set_temp_precision(struct dps310_data *data, int val)
int rc;
u8 shift_en;
- if (val < 0 || val > 128)
+ if (val < 1 || val > 128)
return -EINVAL;
shift_en = val >= 16 ? DPS310_TMP_SHIFT_EN : 0;
@@ -455,7 +455,7 @@ static int dps310_set_pres_samp_freq(struct dps310_data *data, int freq)
{
u8 val;
- if (freq < 0 || freq > 128)
+ if (freq < 1 || freq > 128)
return -EINVAL;
val = ilog2(freq) << 4;
@@ -469,7 +469,7 @@ static int dps310_set_temp_samp_freq(struct dps310_data *data, int freq)
{
u8 val;
- if (freq < 0 || freq > 128)
+ if (freq < 1 || freq > 128)
return -EINVAL;
val = ilog2(freq) << 4;
--
2.43.0