Re: [PATCH v2 RESEND] iio: accel: adxl345: update period cache after successful write
From: Andy Shevchenko
Date: Mon Oct 19 2026 - 06:19:14 EST
On Sun, Oct 18, 2026 at 09:42:00PM +0800, Wenqiang Zhao via B4 Relay 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.
...
> /* 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;
While at it, replace MILLI with MSEC_PER_SEC (from time.h).
> + 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;
Ditto.
> - 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);
Hmm... Okay, since it's three instances and only one you actually touched
perhaps a separate patch.
> - return regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> - DIV_ROUND_CLOSEST(val_fract, 5));
> + return 0;
> }
--
With Best Regards,
Andy Shevchenko