Re: [RFC PATCH v2] cleanup: Add cond_guard() to conditional guards

From: Ira Weiny
Date: Tue Jan 30 2024 - 13:43:43 EST


Dan Williams wrote:
> Fabio M. De Francesco wrote:
> > Add cond_guard() to conditional guards.
> >
> > cond_guard() is used for the _interruptible(), _killable(), and _try
> > versions of locks. It expects a block where the failure can be handled
> > (e.g., calling printk() and returning -EINTR in case of failure).
> >
> > As the other guards, it avoids to open code the release of the lock
> > after a goto to an 'out' label.
> >
> > This remains an RFC because Dan suggested a slightly different syntax:
> >
> > if (cond_guard(...))
> > return -EINTR;
> >
> > But the scoped_cond_guard() macro omits the if statement:
> >
> > scoped_cond_guard (...) {
> > }
> >
> > Thus define cond_guard() similarly to scoped_cond_guard() but with a block
> > to handle the failure case:
> >
> > cond_guard(...)
> > return -EINTR;
>
> That's too subtle for me, because of the mistakes that can be made with
> brackets how about a syntax like:
>
> cond_guard(..., return -EINTR, ...)
>
> ...to make it clear what happens if the lock acquisition fails without
> having to remember there is a hidden incomplete "if ()" statement in
> that macro? More below...

I sympathize with the hidden "if" being confusing but there is already
precedent in the current *_guard macros. So I'd like to know if Peter has
an opinion.

Ira