lkml.org 
[lkml]   [2023]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH 2/4] list.h: Fix parentheses around macro pointer parameter use
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?

> list_for_each_entry((*t2), &testlist, node) { /* works */
> //...
> }
> list_for_each_entry(*t2, &testlist, node) { /* broken */
> //...
> }
> }

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2023-05-04 16:42    [W:0.166 / U:1.748 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site