Re: [PATCH] list: always set pos in list_prepare_entry()

From: Jakob Koschel
Date: Mon Mar 07 2022 - 06:21:48 EST




> On 7. Mar 2022, at 10:49, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> On Sun, Mar 06, 2022 at 05:26:35PM +0100, Jakob Koschel wrote:
>> In order to assign the result from list_prepare_entry() to another
>> variable, it should also be set when pos != NULL.
>>
>> This will be useful once the list iterator is no longer used after
>> the loop.
>
> ...
>
>> #define list_prepare_entry(pos, head, member) \
>> - ((pos) ? : list_entry(head, typeof(*pos), member))
>> + ((pos) ? pos : list_entry(head, typeof(*pos), member))
>
> I'm not sure why then we have () surrounding first pos.
>
> Am I right that the original is an equivalent to
>
> ((pos) ? (pos) : list_entry(head, typeof(*pos), member))
>
> ?

Yes you are right.

I've just tested this again and seems like my local setup was skewed.

My assumption (from some coccinelle output) was that leaving the TRUE case
empty will not do any assignment at all but that's obviously wrong and I
can't reproduce it.

Basically feel free to ignore this PATCH since it just seems to be a NO-OP.

>
> Then what the difference is made by not using parentheses?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

Jakob