public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rojewski, Cezary" <cezary.rojewski@intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [PATCH v2] list: Add a macro to test if entry is pointing to the head
Date: Tue, 29 Sep 2020 14:40:23 +0000	[thread overview]
Message-ID: <5f95bede9603416ca9f1c6ee17d54b35@intel.com> (raw)
In-Reply-To: <20200929134342.51489-1-andriy.shevchenko@linux.intel.com>

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


      reply	other threads:[~2020-09-29 14:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 13:43 [PATCH v2] list: Add a macro to test if entry is pointing to the head Andy Shevchenko
2020-09-29 14:40 ` Rojewski, Cezary [this message]

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=5f95bede9603416ca9f1c6ee17d54b35@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /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