mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iio: accel: adxl345: propagate event regmap errors
@ 2026-10-17  2:38 赵文强
  2026-10-17  2:39 ` [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration 赵文强
  2026-10-17  2:39 ` [PATCH v2 2/2] iio: accel: adxl345: propagate errors when disabling activity events 赵文强
  0 siblings, 2 replies; 5+ messages in thread
From: 赵文强 @ 2026-10-17  2:38 UTC (permalink / raw)
  To: Nuno Sá, Michael Hennerich, Jonathan Cameron
  Cc: David Lechner, Andy Shevchenko, Lothar Rubusch, Joshua Crofts,
	linux, linux-iio, linux-kernel

This two-patch series fixes regmap error propagation in the ADXL345
activity/inactivity event configuration paths:

1. Propagate negative regmap read errors from adxl345_is_act_inact_en()
   in adxl345_read_mag_config() instead of converting them to 1 via !!.
2. Preserve negative errors from adxl345_is_act_inact_ac() when
   disabling activity/inactivity events in adxl345_set_act_inact_en().

Changes in v2:
- Resend with a [PATCH v2 0/2] cover letter, preserving patch line
  lengths and whitespace to address the v1 formatting report
  (thanks to Joshua Crofts).
- No code changes from v1.

Assisted-by: LLM
Signed-off-by: 赵文强 <berringtoni36@gmail.com>
---
赵文强 (2):
  iio: accel: adxl345: propagate errors when reading event configuration
  iio: accel: adxl345: propagate errors when disabling activity events

 drivers/iio/accel/adxl345_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83
-- 
2.50.1 (Apple Git-155)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration
  2026-10-17  2:38 [PATCH v2 0/2] iio: accel: adxl345: propagate event regmap errors 赵文强
@ 2026-10-17  2:39 ` 赵文强
  2026-10-17 18:13   ` Jonathan Cameron
  2026-10-17  2:39 ` [PATCH v2 2/2] iio: accel: adxl345: propagate errors when disabling activity events 赵文强
  1 sibling, 1 reply; 5+ messages in thread
From: 赵文强 @ 2026-10-17  2:39 UTC (permalink / raw)
  To: Nuno Sá, Michael Hennerich, Jonathan Cameron
  Cc: David Lechner, Andy Shevchenko, Lothar Rubusch, Joshua Crofts,
	linux, linux-iio, linux-kernel

adxl345_is_act_inact_en() returns either a boolean state or a negative
regmap error. Applying !! in adxl345_read_mag_config() converts every
negative error to 1, so a failed register read is reported to userspace
as an enabled activity or inactivity event.

Return the helper result directly. Its successful paths already return
0 or 1, and the IIO event attribute read path propagates negative errors.
This also covers the adaptive magnitude events using the same helper.

Fixes: 66a1af6d8a63 ("iio: accel: adxl345: add activity event feature")
Assisted-by: LLM
Signed-off-by: 赵文强 <berringtoni36@gmail.com>
---
Validation on macOS ARM64 with Apple clang 17:
- Compiled the three relevant driver functions verbatim with the driver
  header, using a host regmap stub for deterministic read failures.
- The original code failed 36 error cases; the patch passed all 53 cases.
- Covered activity/inactivity and DC/AC coupling, each of three regmap
  reads failing with -EIO, -ETIMEDOUT and -EREMOTEIO, enabled/disabled
  states, mismatched coupling and an unsupported direction.
- Checked read order, early exit and unchanged register state.
- Used -Wall -Wextra -Werror, AddressSanitizer and UndefinedBehaviorSanitizer.
- git diff --check and checkpatch.pl --no-tree --no-signoff --strict
  on the code diff passed with no errors, warnings or checks.
- The full patch draft also passed checkpatch with no errors, warnings
  or checks after fetching the introducing commit for Fixes validation.

Also compiled adxl345_core.o, adxl345_spi.o and adxl345_i2c.o as
x86_64 ELF relocatable objects using clang and unpacked Debian Linux 6.1
headers supplemented by upstream IIO/regmap headers. This checks syntax
and types; it is not a full Kbuild/modpost build.

No in-kernel KUnit execution or hardware sensor test was performed.
The checkout is sparse; --no-tree disables checkpatch's tree layout
check. Initial draft checks used --no-signoff before human review.
The final signed email also passed checkpatch without --no-signoff.

AI assistance: Codex reviewed the event-read path, identified the errno
conversion, drafted this two-line fix, the reproducer 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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 6c9080d..5983fc7 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -1176,9 +1176,9 @@ static int adxl345_read_mag_config(struct
adxl345_state *st,
 {
 	switch (dir) {
 	case IIO_EV_DIR_RISING:
-		return !!adxl345_is_act_inact_en(st, type_act);
+		return adxl345_is_act_inact_en(st, type_act);
 	case IIO_EV_DIR_FALLING:
-		return !!adxl345_is_act_inact_en(st, type_inact);
+		return adxl345_is_act_inact_en(st, type_inact);
 	default:
 		return -EINVAL;
 	}

base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83
-- 
2.50.1 (Apple Git-155)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] iio: accel: adxl345: propagate errors when disabling activity events
  2026-10-17  2:38 [PATCH v2 0/2] iio: accel: adxl345: propagate event regmap errors 赵文强
  2026-10-17  2:39 ` [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration 赵文强
@ 2026-10-17  2:39 ` 赵文强
  1 sibling, 0 replies; 5+ messages in thread
From: 赵文强 @ 2026-10-17  2:39 UTC (permalink / raw)
  To: Nuno Sá, Michael Hennerich, Jonathan Cameron
  Cc: David Lechner, Andy Shevchenko, Lothar Rubusch, Joshua Crofts,
	linux, linux-iio, linux-kernel

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@gmail.com>
---
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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration
  2026-10-17  2:39 ` [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration 赵文强
@ 2026-10-17 18:13   ` Jonathan Cameron
  2026-10-18  7:40     ` Wenqiang Zhao
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2026-10-17 18:13 UTC (permalink / raw)
  To: 赵文强
  Cc: Nuno Sá,
	Michael Hennerich, David Lechner, Andy Shevchenko,
	Lothar Rubusch, Joshua Crofts, linux, linux-iio, linux-kernel

On Fri, 16 Oct 2026 19:39:08 -0700
赵文强 <berringtoni36@gmail.com> wrote:

> adxl345_is_act_inact_en() returns either a boolean state or a negative

Returning true or false to a function that reports to return integers
is rather nasty and is probably what lead to this bug in the first
place!  Would you mind also changing that as part of this fix?

Cleanest solution is probably to pass a bool * in as a parameter and
use that to 'return' the boolean rather than mixing up bool and error
codes as it currently does.  That will keep the return value for whether
the query succeeded or not.

Thanks,

Jonathan


> regmap error. Applying !! in adxl345_read_mag_config() converts every
> negative error to 1, so a failed register read is reported to userspace
> as an enabled activity or inactivity event.
> 
> Return the helper result directly. Its successful paths already return
> 0 or 1, and the IIO event attribute read path propagates negative errors.
> This also covers the adaptive magnitude events using the same helper.
> 
> Fixes: 66a1af6d8a63 ("iio: accel: adxl345: add activity event feature")
> Assisted-by: LLM
> Signed-off-by: 赵文强 <berringtoni36@gmail.com>

> ---
> Validation on macOS ARM64 with Apple clang 17:
> - Compiled the three relevant driver functions verbatim with the driver
>   header, using a host regmap stub for deterministic read failures.
> - The original code failed 36 error cases; the patch passed all 53 cases.
> - Covered activity/inactivity and DC/AC coupling, each of three regmap
>   reads failing with -EIO, -ETIMEDOUT and -EREMOTEIO, enabled/disabled
>   states, mismatched coupling and an unsupported direction.
> - Checked read order, early exit and unchanged register state.
> - Used -Wall -Wextra -Werror, AddressSanitizer and UndefinedBehaviorSanitizer.
> - git diff --check and checkpatch.pl --no-tree --no-signoff --strict
>   on the code diff passed with no errors, warnings or checks.
> - The full patch draft also passed checkpatch with no errors, warnings
>   or checks after fetching the introducing commit for Fixes validation.
> 
> Also compiled adxl345_core.o, adxl345_spi.o and adxl345_i2c.o as
> x86_64 ELF relocatable objects using clang and unpacked Debian Linux 6.1
> headers supplemented by upstream IIO/regmap headers. This checks syntax
> and types; it is not a full Kbuild/modpost build.
> 
> No in-kernel KUnit execution or hardware sensor test was performed.
> The checkout is sparse; --no-tree disables checkpatch's tree layout
> check. Initial draft checks used --no-signoff before human review.
> The final signed email also passed checkpatch without --no-signoff.
> 
> AI assistance: Codex reviewed the event-read path, identified the errno
> conversion, drafted this two-line fix, the reproducer 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 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 6c9080d..5983fc7 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -1176,9 +1176,9 @@ static int adxl345_read_mag_config(struct
> adxl345_state *st,
>  {
>  	switch (dir) {
>  	case IIO_EV_DIR_RISING:
> -		return !!adxl345_is_act_inact_en(st, type_act);
> +		return adxl345_is_act_inact_en(st, type_act);
>  	case IIO_EV_DIR_FALLING:
> -		return !!adxl345_is_act_inact_en(st, type_inact);
> +		return adxl345_is_act_inact_en(st, type_inact);
>  	default:
>  		return -EINVAL;
>  	}
> 
> base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration
  2026-10-17 18:13   ` Jonathan Cameron
@ 2026-10-18  7:40     ` Wenqiang Zhao
  0 siblings, 0 replies; 5+ messages in thread
From: Wenqiang Zhao @ 2026-10-18  7:40 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Michael Hennerich
  Cc: David Lechner, Andy Shevchenko, Lothar Rubusch, Joshua Crofts,
	linux, linux-iio, linux-kernel

> Cleanest solution is probably to pass a bool * in as a parameter and
> use that to 'return' the boolean rather than mixing up bool and error
> codes as it currently does.

Thanks, Jonathan. I have reworked both the enable-state and coupling
queries to return status separately from bool output parameters, and
updated the event-read, disable and link-bit callers. The 534 host
function-chain cases pass with UBSan; no full kernel build or hardware
test has been performed. I will send v3 after the final review.

Thanks,
Wenqiang


On Sat, 17 Oct 2026 19:13:10 +0100, Jonathan Cameron <jic23@kernel.org> wrote:
> On Fri, 16 Oct 2026 19:39:08 -0700
> 赵文强 <berringtoni36@gmail.com> wrote:
>
> > adxl345_is_act_inact_en() returns either a boolean state or a negative
>
> Returning true or false to a function that reports to return integers
> is rather nasty and is probably what lead to this bug in the first
> place!  Would you mind also changing that as part of this fix?
>
> Cleanest solution is probably to pass a bool * in as a parameter and
> use that to 'return' the boolean rather than mixing up bool and error
> codes as it currently does.  That will keep the return value for whether
> the query succeeded or not.
>
> Thanks,
>
> Jonathan
>
>
> > regmap error. Applying !! in adxl345_read_mag_config() converts every
> > negative error to 1, so a failed register read is reported to userspace
> > as an enabled activity or inactivity event.
> >
> > Return the helper result directly. Its successful paths already return
> > 0 or 1, and the IIO event attribute read path propagates negative errors.
> > This also covers the adaptive magnitude events using the same helper.
> >
> > Fixes: 66a1af6d8a63 ("iio: accel: adxl345: add activity event feature")
> > Assisted-by: LLM
> > Signed-off-by: 赵文强 <berringtoni36@gmail.com>
>
> > ---
> > Validation on macOS ARM64 with Apple clang 17:
> > - Compiled the three relevant driver functions verbatim with the driver
> >   header, using a host regmap stub for deterministic read failures.
> > - The original code failed 36 error cases; the patch passed all 53 cases.
> > - Covered activity/inactivity and DC/AC coupling, each of three regmap
> >   reads failing with -EIO, -ETIMEDOUT and -EREMOTEIO, enabled/disabled
> >   states, mismatched coupling and an unsupported direction.
> > - Checked read order, early exit and unchanged register state.
> > - Used -Wall -Wextra -Werror, AddressSanitizer and UndefinedBehaviorSanitizer.
> > - git diff --check and checkpatch.pl --no-tree --no-signoff --strict
> >   on the code diff passed with no errors, warnings or checks.
> > - The full patch draft also passed checkpatch with no errors, warnings
> >   or checks after fetching the introducing commit for Fixes validation.
> >
> > Also compiled adxl345_core.o, adxl345_spi.o and adxl345_i2c.o as
> > x86_64 ELF relocatable objects using clang and unpacked Debian Linux 6.1
> > headers supplemented by upstream IIO/regmap headers. This checks syntax
> > and types; it is not a full Kbuild/modpost build.
> >
> > No in-kernel KUnit execution or hardware sensor test was performed.
> > The checkout is sparse; --no-tree disables checkpatch's tree layout
> > check. Initial draft checks used --no-signoff before human review.
> > The final signed email also passed checkpatch without --no-signoff.
> >
> > AI assistance: Codex reviewed the event-read path, identified the errno
> > conversion, drafted this two-line fix, the reproducer 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 | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> > index 6c9080d..5983fc7 100644
> > --- a/drivers/iio/accel/adxl345_core.c
> > +++ b/drivers/iio/accel/adxl345_core.c
> > @@ -1176,9 +1176,9 @@ static int adxl345_read_mag_config(struct
> > adxl345_state *st,
> >  {
> >  	switch (dir) {
> >  	case IIO_EV_DIR_RISING:
> > -		return !!adxl345_is_act_inact_en(st, type_act);
> > +		return adxl345_is_act_inact_en(st, type_act);
> >  	case IIO_EV_DIR_FALLING:
> > -		return !!adxl345_is_act_inact_en(st, type_inact);
> > +		return adxl345_is_act_inact_en(st, type_inact);
> >  	default:
> >  		return -EINVAL;
> >  	}
> >
> > base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-18  7:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17  2:38 [PATCH v2 0/2] iio: accel: adxl345: propagate event regmap errors 赵文强
2026-10-17  2:39 ` [PATCH v2 1/2] iio: accel: adxl345: propagate errors when reading event configuration 赵文强
2026-10-17 18:13   ` Jonathan Cameron
2026-10-18  7:40     ` Wenqiang Zhao
2026-10-17  2:39 ` [PATCH v2 2/2] iio: accel: adxl345: propagate errors when disabling activity events 赵文强

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®