[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1785218.VLH7GnMWUR@fdefranc-mobl3>
Date: Tue, 30 Jan 2024 18:55:23 +0100
From: "Fabio M. De Francesco" <fabio.maria.de.francesco@...ux.intel.com>
To: linux-kernel@...r.kernel.org, Dan Williams <dan.j.williams@...el.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Dan Williams <dan.j.williams@...el.com>, Ira Weiny <ira.weiny@...el.com>
Subject: Re: [RFC PATCH v2] cleanup: Add cond_guard() to conditional guards
On Tuesday, 30 January 2024 18:02:09 CET Dan Williams wrote:
> Fabio M. De Francesco wrote:
[skip}
> >
> > @@ -165,6 +174,10 @@ static inline class_##_name##_t
> > class_##_name##ext##_constructor(_init_args) \>
> > #define __guard_ptr(_name) class_##_name##_lock_ptr
> >
> > +#define cond_guard(_name, args...) \
> > + CLASS(_name, scope)(args); \
> > + if (!__guard_ptr(_name)(&scope))
>
> This needs to protect against being used within another if () block.
> Imagine a case of:
>
> if (...) {
> cond_guard(...);
> <statement>
> } else if (...)
Could it be made clear in the documentation that cond_guard() shouldn't be
misused as you showed above?
Actually, I don't know how effective the documentation can be in avoiding
incorrect use of cond_guard().
Fabio
> ...does that "else if" belong to the first "if ()" or the hidden one
> inside the macro?
>
> You can steal the embedded "if ()" trick from scoped_cond_guard() and do
> something like (untested):
>
> #define cond_guard(_name, _fail, args...) \
> CLASS(_name, scope)(args); \
> if (!__guard_ptr(_name)(&scope)) _fail; else /* pass */;
Powered by blists - more mailing lists