From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
David Howells <dhowells@redhat.com>,
Ricardo Martinez <ricardo.martinez@linux.intel.com>
Subject: Re: [RFC PATCH 05/13] list.h: Fix parentheses around macro pointer parameter use
Date: Mon, 8 May 2023 15:16:38 +0300 [thread overview]
Message-ID: <ZFjoJqbDn/BL1GQT@smile.fi.intel.com> (raw)
In-Reply-To: <20230504200527.1935944-6-mathieu.desnoyers@efficios.com>
On Thu, May 04, 2023 at 04:05:19PM -0400, Mathieu Desnoyers wrote:
> Add missing parentheses around use of macro argument "pos" in those
> patterns to ensure operator precedence behaves as expected:
>
> - typeof(*pos)
> - pos->member
> - "x = y" is changed for "x = (y)", because "y" can be an expression
> containing a comma if it is the result of the expansion of a macro such
> as #define eval(...) __VA_ARGS__, which would cause unexpected operator
> precedence. This use-case is far-fetched, but we have to choose one
> way or the other (with or without parentheses) for consistency,
> - x && y is changed for (x) && (y).
>
> Remove useless parentheses around use of macro parameter (head) in the
> following pattern:
>
> - list_is_head(pos, (head))
>
> Because comma is the lowest priority operator already, so the extra pair
> of parentheses is redundant.
But strictly speaking it might be something like
list_...(..., (a, b))
where (a, b) is the head. No?
> This corrects the following usage pattern where operator precedence is
> unexpected:
>
> LIST_HEAD(testlist);
>
> struct test {
> struct list_head node;
> int a;
> };
>
> // pos->member issue
> void f(void)
> {
> struct test *t1;
> struct test **t2 = &t1;
>
> list_for_each_entry((*t2), &testlist, node) { /* works */
> //...
> }
> list_for_each_entry(*t2, &testlist, node) { /* broken */
> //...
Me still in doubt. But it's up to maintainers.
> }
> }
>
> // typeof(*pos) issue
> void f2(void)
> {
> struct test *t1 = NULL, *t2;
>
> t2 = list_prepare_entry((0 + t1), &testlist, node); /* works */
> t2 = list_prepare_entry(0 + t1, &testlist, node); /* broken */
> }
>
> Note that the macros in which "pos" is also used as an lvalue probably
> don't suffer from the lack of parentheses around "pos" in typeof(*pos),
> but add those nevertheless to keep everything consistent.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-05-08 12:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 20:05 [RFC PATCH 00/13] Fix parentheses around macro parameter use in headers Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 01/13] rcu: rcupdate.h: Fix parentheses around macro parameter use Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 02/13] rculist.h: Fix parentheses around macro pointer " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 03/13] rculist_nulls.h: Add " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 04/13] rculist_bl.h: Fix " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 05/13] list.h: " Mathieu Desnoyers
2023-05-08 12:16 ` Andy Shevchenko [this message]
2023-05-08 13:46 ` Mathieu Desnoyers
2023-05-12 11:02 ` Andy Shevchenko
2023-05-12 14:32 ` Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 06/13] list_nulls.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 07/13] list_bl.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 08/13] llist.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 09/13] klist.h: Fix parentheses around macro " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 10/13] resource_ext.h: Remove useless parentheses around macro parameters Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 11/13] netdevice.h: Fix parentheses around macro parameter use Mathieu Desnoyers
2023-05-05 18:44 ` Jakub Kicinski
2023-05-05 18:54 ` Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 12/13] blk-mq.h: " Mathieu Desnoyers
2023-05-05 13:56 ` Mathieu Desnoyers
2023-05-05 18:40 ` Linus Torvalds
2023-05-05 18:49 ` Mathieu Desnoyers
2023-05-05 19:54 ` Linus Torvalds
2023-05-05 20:08 ` Mathieu Desnoyers
2023-05-05 20:22 ` Linus Torvalds
2023-05-05 20:28 ` Mathieu Desnoyers
2023-05-08 14:28 ` Mathieu Desnoyers
2023-05-06 15:45 ` David Laight
2023-05-04 20:05 ` [RFC PATCH 13/13] bio.h: " Mathieu Desnoyers
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=ZFjoJqbDn/BL1GQT@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=ricardo.martinez@linux.intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox