On Fri, 04 Sep 2026 21:24:24 +0200
Wadim Mueller <[email protected]> wrote:

> Li Youhong reported that slf3s_resume() leaves vdd enabled when the
> measurement restart fails [1].  The report is right, but the patch and
> my own Reviewed-by on it were both too narrow.
> 
> Andy asked whether the regulator refcount can go sideways here.  It
> cannot.  device_suspend() sets power.is_suspended only when the callback
> returned 0, and device_resume() returns before the callback when the
> flag is clear.  So the two alternate and the count stays in {0, 1}.
> Please drop my Reviewed-by, the reasoning in it is wrong.
> 
> Three things do go wrong though:
> 
>  - resume enables vdd, start_meas() fails, the supply stays on.
> 
>  - the part is then powered but idle, so it NACKs the stop command.
>    suspend() returns early on that error and never disables vdd, so the
>    system cannot suspend any more until rebind.  This one hurts most.
> 
>  - if regulator_enable() fails in resume, the next suspend disables a
>    supply that was never enabled: "unbalanced disables" in the regulator
>    core, and -EIO.  Unbind hits the same case.
> 
> The original patch fixes the first one only.
> 
> Patch 1 tracks the supply state and drives enable/disable from it.
> Patch 2 adds KUnit tests with a fake i2c adapter and a counting
> regulator, so no hardware is needed:
> 
>   ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/iio/flow
> 
> Four of the eight tests fail without patch 1.
> 
> [1] 
> https://lore.kernel.org/linux-iio/[email protected]/
> 
> Signed-off-by: Wadim Mueller <[email protected]>
Given a few outstanding bits on patch 1 and lack of discussion of patch 2
(which doesn't need to go in as quickly) I am marking this in patchwork
as changes requested.

Thanks

Jonathan

> ---
> Wadim Mueller (2):
>       iio: flow: slf3s: keep the vdd supply balanced across suspend/resume
>       iio: flow: slf3s: add KUnit tests for the PM regulator balance
> 
>  MAINTAINERS                    |   2 +
>  drivers/iio/flow/.kunitconfig  |   6 +
>  drivers/iio/flow/Kconfig       |  15 +
>  drivers/iio/flow/Makefile      |   1 +
>  drivers/iio/flow/slf3s-kunit.c | 734 
> +++++++++++++++++++++++++++++++++++++++++
>  drivers/iio/flow/slf3s.c       |  35 +-
>  6 files changed, 787 insertions(+), 6 deletions(-)
> ---
> base-commit: bc35965f6940a9bf834d54187b6088b8eb09206d
> change-id: 20260904-iio-slf3s-pm-regulator-kunit-43ee079b36f0
> 
> Best regards,


Reply via email to