From: "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com>
To: linux-kernel@vger.kernel.org, Dan Williams <dan.j.williams@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Dan Williams <dan.j.williams@intel.com>,
Ira Weiny <ira.weiny@intel.com>
Subject: Re: [RFC PATCH v2] cleanup: Add cond_guard() to conditional guards
Date: Tue, 30 Jan 2024 18:55:23 +0100 [thread overview]
Message-ID: <1785218.VLH7GnMWUR@fdefranc-mobl3> (raw)
In-Reply-To: <65b92b91a41a8_5cc6f29484@dwillia2-mobl3.amr.corp.intel.com.notmuch>
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 */;
next prev parent reply other threads:[~2024-01-30 17:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 16:38 [RFC PATCH v2] cleanup: Add cond_guard() to conditional guards Fabio M. De Francesco
2024-01-30 17:02 ` Dan Williams
2024-01-30 17:33 ` Fabio M. De Francesco
2024-01-30 17:58 ` Dan Williams
2024-01-31 13:11 ` Fabio M. De Francesco
2024-01-30 17:55 ` Fabio M. De Francesco [this message]
2024-01-30 18:43 ` Ira Weiny
2024-01-30 19:06 ` Dan Williams
2024-01-31 0:04 ` Ira Weiny
2024-01-31 0:43 ` Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1785218.VLH7GnMWUR@fdefranc-mobl3 \
--to=fabio.maria.de.francesco@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.