diff mbox series

[1/2] list: Add list_add_after()

Message ID 20200225111328.25763-1-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series [1/2] list: Add list_add_after() | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (f123417068e51842004bdc047c8c5107b70442ef)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Vasant Hegde Feb. 25, 2020, 11:13 a.m. UTC
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 ccan/list/list.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/ccan/list/list.h b/ccan/list/list.h
index fdeddeb4d..1d75dd92a 100644
--- a/ccan/list/list.h
+++ b/ccan/list/list.h
@@ -183,6 +183,25 @@  static inline void list_add_before(struct list_head *h, struct list_node *n,
 		(void)list_debug(h);
 }
 
+/**
+ * list_add_after - add an entry after another entry.
+ * @h: the list_head to add the node to (we use it for debug purposes, can be NULL)
+ * @n: the list_node to add to the list.
+ * @p: the list_node of the other entry
+ *
+ * The list_node does not need to be initialized; it will be overwritten.
+ */
+static inline void list_add_after(struct list_head *h, struct list_node *n,
+				  struct list_node *p)
+{
+	n->next = p->next;
+	n->prev = p;
+	p->next = n;
+	n->next->prev = n;
+	if (h)
+		(void)list_debug(h);
+}
+
 /**
  * list_add_tail - add an entry at the end of a linked list.
  * @h: the list_head to add the node to