* [PATCH v2] iio: accel: adxl345: update period cache after successful write
@ 2026-10-17 9:48 Wenqiang Zhao
2026-10-17 18:50 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Wenqiang Zhao @ 2026-10-17 9:48 UTC (permalink / raw)
To: Nuno Sá, Michael Hennerich, Jonathan Cameron
Cc: David Lechner, Andy Shevchenko, linux, linux-iio, linux-kernel
The ADXL345 event-period read path returns st->inact_time_ms. The setters
for inactivity, free-fall and the ODR-derived default currently update
this cache before writing TIME_INACT or TIME_FF. If the regmap write
fails, the sysfs write reports an error but a subsequent read returns
the requested period even though it was not programmed.
Update the cached period only after the corresponding regmap write
succeeds.
Fixes: 8a1536cc4a1c ("iio: accel: adxl345: add inactivity feature")
Fixes: f6f22950d925 ("iio: accel: adxl345: extend inactivity time for
less than 1s")
Assisted-by: LLM
Signed-off-by: Wenqiang Zhao <berringtoni36@gmail.com>
---
v2:
- Keep Fixes: tags on a single line (Nuno)
- Use a Latin-script name in From: and Signed-off-by: (Nuno)
- Drop the long validation notes; build-tested only, not tested on hardware
The missing serialization between concurrent sysfs callers that Nuno
pointed out is a separate issue and will be addressed in a follow-up
patch.
drivers/iio/accel/adxl345_core.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 6c9080d..cd58304 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -391,30 +391,47 @@ static int adxl345_set_default_time(struct
adxl345_state *st)
odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval);
val = clamp(max_boundary - adxl345_odr_tbl[odr][0],
min_boundary, max_boundary);
- st->inact_time_ms = MILLI * val;
/* Inactivity time in s */
- return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
+ ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
+ if (ret)
+ return ret;
+
+ st->inact_time_ms = MILLI * val;
+
+ return 0;
}
static int adxl345_set_inactivity_time(struct adxl345_state *st, u32 val_int)
{
+ int ret;
+
+ ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
+ if (ret)
+ return ret;
+
st->inact_time_ms = MILLI * val_int;
- return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
+ return 0;
}
static int adxl345_set_freefall_time(struct adxl345_state *st, u32 val_fract)
{
+ int ret;
+
/*
* Datasheet max. value is 255 * 5000 us = 1.275000 seconds.
*
* Recommended values between 100ms and 350ms (0x14 to 0x46)
*/
+ ret = regmap_write(st->regmap, ADXL345_REG_TIME_FF,
+ DIV_ROUND_CLOSEST(val_fract, 5));
+ if (ret)
+ return ret;
+
st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI);
- return regmap_write(st->regmap, ADXL345_REG_TIME_FF,
- DIV_ROUND_CLOSEST(val_fract, 5));
+ return 0;
}
/**
base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] iio: accel: adxl345: update period cache after successful write
2026-10-17 9:48 [PATCH v2] iio: accel: adxl345: update period cache after successful write Wenqiang Zhao
@ 2026-10-17 18:50 ` Jonathan Cameron
2026-10-18 7:40 ` Wenqiang Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2026-10-17 18:50 UTC (permalink / raw)
To: Wenqiang Zhao
Cc: Nuno Sá,
Michael Hennerich, David Lechner, Andy Shevchenko, linux,
linux-iio, linux-kernel
On Sat, 17 Oct 2026 04:48:25 -0500
Wenqiang Zhao <berringtoni36@gmail.com> wrote:
> The ADXL345 event-period read path returns st->inact_time_ms. The setters
> for inactivity, free-fall and the ODR-derived default currently update
> this cache before writing TIME_INACT or TIME_FF. If the regmap write
> fails, the sysfs write reports an error but a subsequent read returns
> the requested period even though it was not programmed.
>
> Update the cached period only after the corresponding regmap write
> succeeds.
>
> Fixes: 8a1536cc4a1c ("iio: accel: adxl345: add inactivity feature")
> Fixes: f6f22950d925 ("iio: accel: adxl345: extend inactivity time for
> less than 1s")
> Assisted-by: LLM
> Signed-off-by: Wenqiang Zhao <berringtoni36@gmail.com>
> ---
> v2:
> - Keep Fixes: tags on a single line (Nuno)
Sadly I think your email client or server is fighting back. I'm still
seeing the split one. If that isn't easy to fix, look at using b4 and the
web gateway that can use. Avoids any opportunity for email corruption.
> - Use a Latin-script name in From: and Signed-off-by: (Nuno)
> - Drop the long validation notes; build-tested only, not tested on hardware
>
> The missing serialization between concurrent sysfs callers that Nuno
> pointed out is a separate issue and will be addressed in a follow-up
> patch.
>
> drivers/iio/accel/adxl345_core.c | 27 ++++++++++++++++++++++-----
> 1 file changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 6c9080d..cd58304 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -391,30 +391,47 @@ static int adxl345_set_default_time(struct
> adxl345_state *st)
> odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval);
> val = clamp(max_boundary - adxl345_odr_tbl[odr][0],
> min_boundary, max_boundary);
> - st->inact_time_ms = MILLI * val;
>
> /* Inactivity time in s */
> - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> + ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> + if (ret)
> + return ret;
> +
> + st->inact_time_ms = MILLI * val;
> +
> + return 0;
> }
>
> static int adxl345_set_inactivity_time(struct adxl345_state *st, u32 val_int)
> {
> + int ret;
> +
> + ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
> + if (ret)
> + return ret;
> +
> st->inact_time_ms = MILLI * val_int;
>
> - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
> + return 0;
> }
>
> static int adxl345_set_freefall_time(struct adxl345_state *st, u32 val_fract)
> {
> + int ret;
> +
> /*
> * Datasheet max. value is 255 * 5000 us = 1.275000 seconds.
> *
> * Recommended values between 100ms and 350ms (0x14 to 0x46)
> */
> + ret = regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> + DIV_ROUND_CLOSEST(val_fract, 5));
> + if (ret)
> + return ret;
> +
> st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI);
>
> - return regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> - DIV_ROUND_CLOSEST(val_fract, 5));
> + return 0;
> }
>
> /**
>
> base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] iio: accel: adxl345: update period cache after successful write
2026-10-17 18:50 ` Jonathan Cameron
@ 2026-10-18 7:40 ` Wenqiang Zhao
0 siblings, 0 replies; 3+ 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, linux, linux-iio, linux-kernel
> If that isn't easy to fix, look at using b4 and the
> web gateway that can use.
Thanks for flagging this, Jonathan. The sent-folder checks did not
catch the corruption seen on receipt. I will switch to b4 and the web
submission endpoint, and resend the unchanged period-cache patch once
that setup is verified.
Thanks,
Wenqiang
On Sat, 17 Oct 2026 19:50:37 +0100, Jonathan Cameron <jic23@kernel.org> wrote:
> On Sat, 17 Oct 2026 04:48:25 -0500
> Wenqiang Zhao <berringtoni36@gmail.com> wrote:
>
> > The ADXL345 event-period read path returns st->inact_time_ms. The setters
> > for inactivity, free-fall and the ODR-derived default currently update
> > this cache before writing TIME_INACT or TIME_FF. If the regmap write
> > fails, the sysfs write reports an error but a subsequent read returns
> > the requested period even though it was not programmed.
> >
> > Update the cached period only after the corresponding regmap write
> > succeeds.
> >
> > Fixes: 8a1536cc4a1c ("iio: accel: adxl345: add inactivity feature")
> > Fixes: f6f22950d925 ("iio: accel: adxl345: extend inactivity time for
> > less than 1s")
> > Assisted-by: LLM
> > Signed-off-by: Wenqiang Zhao <berringtoni36@gmail.com>
> > ---
> > v2:
> > - Keep Fixes: tags on a single line (Nuno)
>
> Sadly I think your email client or server is fighting back. I'm still
> seeing the split one. If that isn't easy to fix, look at using b4 and the
> web gateway that can use. Avoids any opportunity for email corruption.
>
> > - Use a Latin-script name in From: and Signed-off-by: (Nuno)
> > - Drop the long validation notes; build-tested only, not tested on hardware
> >
> > The missing serialization between concurrent sysfs callers that Nuno
> > pointed out is a separate issue and will be addressed in a follow-up
> > patch.
> >
> > drivers/iio/accel/adxl345_core.c | 27 ++++++++++++++++++++++-----
> > 1 file changed, 22 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> > index 6c9080d..cd58304 100644
> > --- a/drivers/iio/accel/adxl345_core.c
> > +++ b/drivers/iio/accel/adxl345_core.c
> > @@ -391,30 +391,47 @@ static int adxl345_set_default_time(struct
> > adxl345_state *st)
> > odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval);
> > val = clamp(max_boundary - adxl345_odr_tbl[odr][0],
> > min_boundary, max_boundary);
> > - st->inact_time_ms = MILLI * val;
> >
> > /* Inactivity time in s */
> > - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> > + ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> > + if (ret)
> > + return ret;
> > +
> > + st->inact_time_ms = MILLI * val;
> > +
> > + return 0;
> > }
> >
> > static int adxl345_set_inactivity_time(struct adxl345_state *st, u32 val_int)
> > {
> > + int ret;
> > +
> > + ret = regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
> > + if (ret)
> > + return ret;
> > +
> > st->inact_time_ms = MILLI * val_int;
> >
> > - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
> > + return 0;
> > }
> >
> > static int adxl345_set_freefall_time(struct adxl345_state *st, u32 val_fract)
> > {
> > + int ret;
> > +
> > /*
> > * Datasheet max. value is 255 * 5000 us = 1.275000 seconds.
> > *
> > * Recommended values between 100ms and 350ms (0x14 to 0x46)
> > */
> > + ret = regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> > + DIV_ROUND_CLOSEST(val_fract, 5));
> > + if (ret)
> > + return ret;
> > +
> > st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI);
> >
> > - return regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> > - DIV_ROUND_CLOSEST(val_fract, 5));
> > + return 0;
> > }
> >
> > /**
> >
> > base-commit: 9ee8306121495d2a25aa5d1bfd519f2748786b83
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-18 7:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17 9:48 [PATCH v2] iio: accel: adxl345: update period cache after successful write Wenqiang Zhao
2026-10-17 18:50 ` Jonathan Cameron
2026-10-18 7:40 ` Wenqiang Zhao
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®