Re: [PATCH v2 2/3] iio: accel: adxl380: Introduce helper function for activity detection
From: Jonathan Cameron
Date: Fri Jan 16 2026 - 14:32:45 EST
On Thu, 15 Jan 2026 22:28:05 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> On Thu, Jan 15, 2026 at 06:53:49PM +0100, Francesco Lavra wrote:
> > Motion detection functionalities (such as activity and inactivity
> > detection) are only available when the chip is in a low-power mode; this
> > affects the available sampling frequency values.
> > In preparation for adding support for a new frequency value, introduce a
> > helper function that checks whether activity/inactivity detection is
> > currently enabled; this function will be reused in a future commit to
> > determine what frequency values are available at any given time.
> > No functional changes.
>
> ...
>
> > +static int adxl380_act_inact_enabled(struct adxl380_state *st, bool *enabled)
> > +{
> > + unsigned int act_inact_ctl;
> > + int ret;
> > +
> > + if (!st->chip_info->has_low_power) {
> > + *enabled = false;
> > + return 0;
> > + }
> > +
> > + ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl);
>
> > + if (!ret)
>
> What's wrong with the standard pattern?
>
> if (ret)
> return ret;
>
> > + *enabled = FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) ||
> > + FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl);
> > +
> > + return ret;
>
> return 0;
>
Fully agreed. Whilst it's a tiny bit longer, it is a lot more consistent
to always handle errors out of line and good flow inline.
Jonathan
> > +}
>
>