Re: [PATCH 6/6] regulator: core: simplify lock_two()
From: Michał Mirosław
Date: Mon Aug 28 2023 - 16:27:51 EST
On Mon, Aug 21, 2023 at 09:51:08AM -0700, Doug Anderson wrote:
> Hi,
>
> On Sat, Aug 19, 2023 at 3:46 PM Michał Mirosław <mirq-linux@xxxxxxxxxxxx> wrote:
> >
> > Make regulator_lock_two() shorter by observing that we have only two
> > locks and when swapped earlier the retry code becomes identical to the
> > normal (optimistic) path.
> >
> > Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
> > ---
> > drivers/regulator/core.c | 28 ++++++++++------------------
> > 1 file changed, 10 insertions(+), 18 deletions(-)
>
> This is quite nearly a direct revert of commit 37473397b852
> ("regulator: core: Make regulator_lock_two() logic easier to follow"),
> which was requested by Stephen in:
>
> https://lore.kernel.org/r/CAE-0n53Eb1BeDPmjBycXUaQAF4ppiAM6UDWje_jiB9GAmR8MMw@xxxxxxxxxxxxxx
>
> I don't personally have a strong opinion, but do prefer not to flip-flop. ;-)
Indeed they are quite similar. I did remove a bit more code than that,
though: in this case there is no early success return before the loop.
Instead of saying:
lock A
lock B
if ok return
if that failed, loop:
unlock A
lock B harder
lock A
if ok return
swap A <-> B
lock B
Now it's:
lock A
loop forever:
lock B
if ok, return
unlock A
swap them
lock A harder
With the same condition 'A held' at the start of an iteration.
Best Regards
Michał Mirosław