All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Jihong <yangjihong1@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@kernel.org>, <namhyung@kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>
Cc: <yangjihong1@huawei.com>
Subject: [RFC 05/13] tools lib: Add list_last_entry_or_null
Date: Mon, 13 Jun 2022 17:45:57 +0800	[thread overview]
Message-ID: <20220613094605.208401-6-yangjihong1@huawei.com> (raw)
In-Reply-To: <20220613094605.208401-1-yangjihong1@huawei.com>

Add list_last_entry_or_null to get the last element from a list,
returns NULL if the list is empty.

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 tools/include/linux/list.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/include/linux/list.h b/tools/include/linux/list.h
index b2fc48d5478c..a4dfb6a7cc6a 100644
--- a/tools/include/linux/list.h
+++ b/tools/include/linux/list.h
@@ -384,6 +384,17 @@ static inline void list_splice_tail_init(struct list_head *list,
 #define list_first_entry_or_null(ptr, type, member) \
 	(!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
 
+/**
+ * list_last_entry_or_null - get the last element from a list
+ * @ptr:       the list head to take the element from.
+ * @type:      the type of the struct this is embedded in.
+ * @member:    the name of the list_head within the struct.
+ *
+ * Note that if the list is empty, it returns NULL.
+ */
+#define list_last_entry_or_null(ptr, type, member) \
+	(!list_empty(ptr) ? list_last_entry(ptr, type, member) : NULL)
+
 /**
  * list_next_entry - get the next element in list
  * @pos:	the type * to cursor
-- 
2.30.GIT


  parent reply	other threads:[~2022-06-13  9:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13  9:45 [RFC 00/13] perf: Add perf kwork Yang Jihong
2022-06-13  9:45 ` [RFC 01/13] perf kwork: New tool Yang Jihong
2022-06-14 21:43   ` Namhyung Kim
2022-06-15  1:38     ` Yang Jihong
2022-06-13  9:45 ` [RFC 02/13] perf kwork: Add irq record support Yang Jihong
2022-06-13  9:45 ` [RFC 03/13] perf kwork: Add softirq " Yang Jihong
2022-06-13  9:45 ` [RFC 04/13] perf kwork: Add workqueue " Yang Jihong
2022-06-13  9:45 ` Yang Jihong [this message]
2022-06-13  9:45 ` [RFC 06/13] perf kwork: Implement perf kwork report Yang Jihong
2022-06-14 21:49   ` Namhyung Kim
2022-06-15  3:12     ` Yang Jihong
2022-06-15 22:01       ` Namhyung Kim
2022-06-16  1:31         ` Yang Jihong
2022-06-13  9:45 ` [RFC 07/13] perf kwork: Add irq report support Yang Jihong
2022-06-13  9:46 ` [RFC 08/13] perf kwork: Add softirq " Yang Jihong
2022-06-13  9:46 ` [RFC 09/13] perf kwork: Add workqueue " Yang Jihong
2022-06-14 21:54   ` Namhyung Kim
2022-06-15  3:22     ` Yang Jihong
2022-06-15 21:56       ` Namhyung Kim
2022-06-16  1:42         ` Yang Jihong
2022-06-13  9:46 ` [RFC 10/13] perf kwork: Implement perf kwork latency Yang Jihong
2022-06-13  9:46 ` [RFC 11/13] perf kwork: Add softirq latency support Yang Jihong
2022-06-13  9:46 ` [RFC 12/13] perf kwork: Add workqueue " Yang Jihong
2022-06-13  9:46 ` [RFC 13/13] perf kwork: Implement perf kwork timehist Yang Jihong
2022-06-22 14:59 ` [RFC 00/13] perf: Add perf kwork Paul A. Clarke
2022-06-23  1:02   ` Yang Jihong
2022-06-23 14:25     ` Paul A. Clarke
2022-06-24  1:26       ` Yang Jihong

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=20220613094605.208401-6-yangjihong1@huawei.com \
    --to=yangjihong1@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.