* [PATCH] list: always set pos in list_prepare_entry()
@ 2022-03-06 16:26 Jakob Koschel
2022-03-07 9:49 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Jakob Koschel @ 2022-03-06 16:26 UTC (permalink / raw)
To: Linus Torvalds
Cc: Jakob Koschel, linux-kernel, Andrew Morton, Andy Shevchenko,
Greg Kroah-Hartman, Mike Rapoport, Brian Johannesmeyer,
Cristiano Giuffrida, Bos, H.J.
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.
The original code:
list_for_each_entry(fl, head, list) {
if (...)
break;
}
list_for_each_entry_continue(fl, head, list) {
}
can then just be turned into something like this:
list_for_each_entry(fl, head, list) {
if (...) {
tmp = fl;
break;
}
}
fl = list_prepare_entry(tmp, head, list);
list_for_each_entry_continue(fl, head, list) {
}
The compiler should happily optimize away the
TRUE case if the variable being assigned is the same:
pos = list_prepare_entry(pos, head, list);
and only do it in the case where the variable to assign
is different:
pos = list_prepare_entry(tmp, head, list);
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
include/linux/list.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/list.h b/include/linux/list.h
index dd6c2041d09c..050747fb5ea8 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -659,7 +659,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* Prepares a pos entry for use as a start point in list_for_each_entry_continue().
*/
#define list_prepare_entry(pos, head, member) \
- ((pos) ? : list_entry(head, typeof(*pos), member))
+ ((pos) ? pos : list_entry(head, typeof(*pos), member))
/**
* list_for_each_entry_continue - continue iteration over list of given type
base-commit: 719fce7539cd3e186598e2aed36325fe892150cf
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] list: always set pos in list_prepare_entry()
2022-03-06 16:26 [PATCH] list: always set pos in list_prepare_entry() Jakob Koschel
@ 2022-03-07 9:49 ` Andy Shevchenko
2022-03-07 10:47 ` Jakob Koschel
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2022-03-07 9:49 UTC (permalink / raw)
To: Jakob Koschel
Cc: Linus Torvalds, linux-kernel, Andrew Morton, Greg Kroah-Hartman,
Mike Rapoport, Brian Johannesmeyer, Cristiano Giuffrida, Bos,
H.J.
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))
?
Then what the difference is made by not using parentheses?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] list: always set pos in list_prepare_entry()
2022-03-07 9:49 ` Andy Shevchenko
@ 2022-03-07 10:47 ` Jakob Koschel
0 siblings, 0 replies; 3+ messages in thread
From: Jakob Koschel @ 2022-03-07 10:47 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Torvalds, Linux Kernel Mailing List, Andrew Morton,
Greg Kroah-Hartman, Mike Rapoport, Brian Johannesmeyer,
Cristiano Giuffrida, Bos, H.J.
> On 7. Mar 2022, at 10:49, Andy Shevchenko <andriy.shevchenko@linux.intel.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-07 11:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-06 16:26 [PATCH] list: always set pos in list_prepare_entry() Jakob Koschel
2022-03-07 9:49 ` Andy Shevchenko
2022-03-07 10:47 ` Jakob Koschel
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®