Re: [PATCH v3 7/9] iio: imu: st_lsm6dsx: add event configurability on a per axis basis

From: Andy Shevchenko
Date: Tue Nov 25 2025 - 15:38:29 EST


On Tue, Nov 25, 2025 at 09:23:05PM +0100, Francesco Lavra wrote:
> In order to be able to configure event detection on a per axis
> basis (for either setting an event threshold/sensitivity value, or
> enabling/disabling event detection), add new axis-specific fields
> to struct st_lsm6dsx_event_src, and modify the logic that handles
> event configuration to properly handle axis-specific settings when
> supported by a given event source.
> A future commit will add actual event sources with per-axis
> configurability.

...

> + /*
> + * If the set of axes for which the event source is enabled does not
> + * change from empty to non-empty or vice versa, there is nothing else
> + * to do.
> + */
> + old_enable = hw->enable_event[event];
> + new_enable = state ? (old_enable | BIT(axis)) :
> + (old_enable & ~BIT(axis));
> + if (!!old_enable == !!new_enable)
> + return 0;

Sorry, I had no time to answer to you on previous round.
I read and found that I was mistaken assuming that the axis
is the bit that appears to be last when doing something here.
Without that assumption my approach (obviously) won't work.

However, the !! here is also not needed, the

if (!old_enable == !new_enable)

will work the same way. This will address my concerns about double negation and
makes code easier to understand as we don't need to implicitly convert integers
to booleans and than back to integers.

(and yes, I run the updated test cases to see it works as expected).

--
With Best Regards,
Andy Shevchenko