From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Cezary Rojewski <cezary.rojewski@intel.com>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1] list: Add a macro to test if entry is pointing to the head
Date: Tue, 29 Sep 2020 14:28:56 +0300 [thread overview]
Message-ID: <20200929112856.41771-1-andriy.shevchenko@linux.intel.com> (raw)
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/list.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/list.h b/include/linux/list.h
index 796975c3c35c..49efaa8c3403 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -770,6 +770,17 @@ static inline void list_splice_tail_init(struct list_head *list,
#define list_safe_reset_next(pos, n, member) \
n = list_next_entry(pos, member)
+/**
+ * list_entry_is_head - test if the entry points to the head of the list
+ * @pos: the type * to cursor
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * This macro can be used to check if the loop over the list wasn't stopped.
+ */
+#define list_entry_is_head(pos, head, member) \
+ (&pos->member == (head))
+
/*
* Double linked lists with a single pointer list head.
* Mostly useful for hash tables where the two pointer list head is
--
2.28.0
reply other threads:[~2020-09-29 11:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200929112856.41771-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=cezary.rojewski@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
all inboxes | Powered by JetHome®