[PATCH 2/2] iio: accel: adxl345: propagate errors when disabling activity events
From: 赵文强
Date: Sun Oct 11 2026 - 02:16:12 EST
When disabling an activity or inactivity event in
adxl345_set_act_inact_en(), adxl345_is_act_inact_ac() is called to
verify that the currently configured AC/DC coupling matches the event
being disabled.
adxl345_is_act_inact_ac() returns 1 on a coupling match, 0 on a
coupling mismatch, or a negative errno if regmap_read() fails. Checking
<= 0 and unconditionally returning 0 swallows negative regmap errors
and reports a successful write to userspace while leaving the event
enabled in registers.
Store the helper return value in ret and return ret when ret <= 0 so
mismatched coupling still returns 0 while negative regmap errors are
propagated.
Fixes: 31f7679bb69a ("iio: accel: adxl345: add coupling detection for
activity/inactivity")
Assisted-by: LLM
Signed-off-by: 赵文强 <berringtoni36@xxxxxxxxx>
---
Validation on macOS ARM64 with Apple clang 17:
- Compiled the seven event-write/disable driver functions verbatim with
the driver header, using a host regmap stub for deterministic read
failures and register state checks.
- The original code failed all 12 disable regmap-error cases (returning 0
instead of -EIO, -ETIMEDOUT and -EREMOTEIO); the patch passed all 29
cases across DC/AC activity and inactivity disable error propagation,
coupling-mismatch ignore, normal disable, normal enable, enable read
failure and unsupported direction.
- Verified that failed disable reads exit after the first regmap_read()
without issuing register writes or altering enabled register bits.
- Used -Wall -Wextra -Werror, AddressSanitizer and UndefinedBehaviorSanitizer.
- Also compiled adxl345_core.o, adxl345_spi.o and adxl345_i2c.o as 64-bit
x86_64 ELF relocatable objects with clang --target=x86_64-unknown-linux-gnu
against unpacked Debian Linux 6.1 headers plus upstream IIO/regmap headers.
- git diff --check and checkpatch.pl --no-tree --no-signoff --strict
passed with 0 errors, 0 warnings and 0 checks.
This is a host function-chain regression and cross-target object compile,
not an in-kernel Kbuild/KUnit execution or hardware sensor test.
AI assistance: Antigravity identified the error-swallowing check in
adxl345_set_act_inact_en(), drafted this fix, the fault-injection test
and changelog.
The request was to prepare a driver/BSP/kernel contribution related to
an ADXL345 SPI/IIO vibration-monitoring project with reproduction and checks.
drivers/iio/accel/adxl345_core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 5983fc7..8ec1bbc 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -692,8 +692,9 @@ static int adxl345_set_act_inact_en(struct
adxl345_state *st,
* current call attempts to turn off a DC-coupled activity, this
* inconsistency should be detected here.
*/
- if (adxl345_is_act_inact_ac(st, type) <= 0)
- return 0;
+ ret = adxl345_is_act_inact_ac(st, type);
+ if (ret <= 0)
+ return ret;
}
/* Start modifying configuration registers */
--
2.50.1 (Apple Git-155)