[PATCH 04/15] iio: accel: adxl380: don't stay in standby on -EINVAL
From: Greg Kroah-Hartman
Date: Tue Oct 27 2026 - 12:36:45 EST
From: Josef Bacik <josef@xxxxxxxxxxxxxx>
adxl380_set_act_inact_threshold() puts the sensor into standby, writes the
threshold and switches the measurement on again. A threshold above 8191 is
refused in between, and the sensor stays in standby: no samples and no
events until the next write that succeeds.
adxl380_set_range() has the same problem and a worse one. It rescales both
thresholds for the new range. If one no longer fits it returns -EINVAL
with the sensor in standby, the new range in the chip, the old one in
st->range and rescaled thresholds in the driver's state: from the next
successful write on the samples are reported with the wrong scale.
Switch the measurement on again if the threshold is refused. In
adxl380_set_range() see whether the thresholds fit before anything is
changed.
Fixes: df36de13677a ("iio: accel: add ADXL380 driver")
Cc: stable <stable@xxxxxxxxxx>
Cc: Ramona Gradinariu <ramona.gradinariu@xxxxxxxxxx>
Cc: Antoniu Miclaus <antoniu.miclaus@xxxxxxxxxx>
Cc: "Nuno Sá" <nuno.sa@xxxxxxxxxx>
Cc: Michael Hennerich <Michael.Hennerich@xxxxxxxxxx>
Cc: David Lechner <dlechner@xxxxxxxxxxxx>
Cc: Andy Shevchenko <andy@xxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/iio/accel/adxl380.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
index 8518ee23e114..03b140303520 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -334,8 +334,11 @@ static int adxl380_set_act_inact_threshold(struct iio_dev *indio_dev,
return ret;
ret = adxl380_write_act_inact_threshold(st, act, th);
- if (ret)
+ if (ret) {
+ /* Leave standby also if the value was refused */
+ adxl380_set_measure_en(st, true);
return ret;
+ }
return adxl380_set_measure_en(st, true);
}
@@ -698,6 +701,12 @@ static int adxl380_set_range(struct adxl380_state *st, u8 range)
guard(mutex)(&st->lock);
+ /* The thresholds are rescaled: see that they fit before any change */
+ if (mult_frac(max(st->act_threshold, st->inact_threshold),
+ adxl380_range_scale_factor_tbl[st->range],
+ adxl380_range_scale_factor_tbl[range]) > ADXL380_THRESH_MAX)
+ return -EINVAL;
+
ret = adxl380_set_measure_en(st, false);
if (ret)
return ret;
--
2.56.0