From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.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 2/4] list.h: Fix parentheses around macro pointer parameter use
Date: Thu, 4 May 2023 10:45:18 -0400 [thread overview]
Message-ID: <532c91c5-5655-2a15-8bf1-82ee939c156b@efficios.com> (raw)
In-Reply-To: <ZFPEEVvHTw2uukun@smile.fi.intel.com>
On 2023-05-04 10:41, Andy Shevchenko wrote:
> On Wed, May 03, 2023 at 09:29:12PM -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
>>
>> 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.
>>
>> 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;
>
> I'm not against the patch, but I'm in doubt, looking into this example, it's useful.
> Any real use case like above in the Linux kernel, please?
There aren't because the code would not compile with the current header
implementation. But it's unexpected that this kind of pattern does not work.
It's not about being useful, but rather about eliminating unexpected
operator precedence within macros, and about being consistent everywhere.
Thanks,
Mathieu
>
>> list_for_each_entry((*t2), &testlist, node) { /* works */
>> //...
>> }
>> list_for_each_entry(*t2, &testlist, node) { /* broken */
>> //...
>> }
>> }
>
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2023-05-04 14:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 1:29 [RFC PATCH 1/4] rcu: rcupdate.h: Add missing parentheses around macro pointer dereference Mathieu Desnoyers
2023-05-04 1:29 ` [RFC PATCH 2/4] list.h: Fix parentheses around macro pointer parameter use Mathieu Desnoyers
2023-05-04 14:41 ` Andy Shevchenko
2023-05-04 14:45 ` Mathieu Desnoyers [this message]
2023-05-04 1:29 ` [RFC PATCH 3/4] rculist.h: " Mathieu Desnoyers
2023-05-04 16:19 ` Joel Fernandes
2023-05-05 14:06 ` Steven Rostedt
2023-05-05 14:35 ` Joel Fernandes
2023-05-05 15:02 ` Steven Rostedt
2023-05-04 1:29 ` [RFC PATCH 4/4] llist.h: " Mathieu Desnoyers
2023-05-04 5:54 ` Huang, Ying
2023-05-04 14:54 ` Mathieu Desnoyers
2023-05-04 17:16 ` Linus Torvalds
2023-05-05 1:38 ` Huang, Ying
2023-05-05 14:23 ` Mathieu Desnoyers
2023-05-05 18:08 ` Linus Torvalds
2023-05-06 1:12 ` Huang, Ying
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=532c91c5-5655-2a15-8bf1-82ee939c156b@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dhowells@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®