lkml.org 
[lkml]   [2020]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2] list: Add a macro to test if entry is pointing to the head
Date
On 2020-09-29 3:43 PM, Andy Shevchenko wrote:
> Add a macro to test if entry is pointing to the head of the list
> which is useful in cases like:
>
> list_for_each_entry(pos, &head, member) {
> if (cond)
> break;
> }
> if (list_entry_is_head(pos, &head, member))
> return -ERRNO;
>
> that allows to avoid additional variable to be added to track if loop
> has not been stopped in the middle.
>
> While here, convert list_for_each_entry*() family of macros to use a new one.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: converted users inside list.h, dropped ambiguous description

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>

This is a good addition to the list of helper macros found in list.h.

When looking at below:

> /**
> * list_for_each_entry - iterate over list of given type
> * @pos: the type * to use as a loop cursor.
> @@ -617,7 +626,7 @@ static inline void list_splice_tail_init(struct list_head *list,
> */
> #define list_for_each_entry(pos, head, member) \
> for (pos = list_first_entry(head, typeof(*pos), member); \
> - &pos->member != (head); \
> + !list_entry_is_head(pos, head, member); \
> pos = list_next_entry(pos, member))
>

it seems such helper should have been here a long time ago (notice the
usage of helpers for initial assignment and cursor update while the
loop-exit check was devoid of such).

Czarek

\
 
 \ /
  Last update: 2020-09-29 16:41    [W:0.030 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site