Skip to contentSkip to conversation

llist: Make llist_del_first return only the first node

PATCH RESEND In review liqiang 2 participants 3 messages Feb 18, 2024 Library code

lore
Share & tools
lore

liqiang

author
#0 lore raw

PATCH RESEND 1/1 llist: Make llist_del_first return only the first node

Set the next of the returned node of llist_del_first to NULL, which can prevent subsequent nodes in llist from being exposed, and is more consistent with the logic of this interface.

---
 lib/llist.c | 1 +
 1 file changed, 1 insertion(+)
lib/llist.c +1 -0
index f21d0cf..c33fff5 100644
@@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
 		next = READ_ONCE(entry->next);
 	} while (!try_cmpxchg(&head->first, &entry, next));
 
+	entry->next = NULL;
 	return entry;
 }
 EXPORT_SYMBOL_GPL(llist_del_first);
Signature · 1 line
2.23.0.windows.1
#1 lore raw
Quoted 15 lines · liqiang

Set the next of the returned node of llist_del_first to NULL, which can prevent subsequent nodes in llist from being exposed, and is more consistent with the logic of this interface.

---
 lib/llist.c | 1 +
 1 file changed, 1 insertion(+)
lib/llist.c +0 -0
index f21d0cf..c33fff5 100644

lib/llist.c struct llist_node *llist_del_first(struct llist_head *head) · line 67

Quoted 7 lines
lib/llist.c +1 -0
@@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
 		next = READ_ONCE(entry->next);
 	} while (!try_cmpxchg(&head->first, &entry, next));
 
+	entry->next = NULL;
 	return entry;
 }
 EXPORT_SYMBOL_GPL(llist_del_first);

This isn't needed for functionality correctness. Many users of llist ask for performance. So, it may be better to let the users to decide whether to set entry->next to NULL.

--
Best Regards,
Huang, Ying

author
#2 lore raw
Quoted 20 lines · Ying
Quoted 18 lines · liqiang

Set the next of the returned node of llist_del_first to NULL, which can prevent subsequent nodes in llist from being exposed, and is more consistent with the logic of this interface.

---
 lib/llist.c | 1 +
 1 file changed, 1 insertion(+)
lib/llist.c +0 -0
index f21d0cf..c33fff5 100644
@@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
 		next = READ_ONCE(entry->next);
 	} while (!try_cmpxchg(&head->first, &entry, next));
 
Quoted 9 lines

lib/llist.c struct llist_node *llist_del_first(struct llist_head *head) · line 67

Quoted 4 lines
lib/llist.c +1 -0
+	entry->next = NULL;
 	return entry;
 }
 EXPORT_SYMBOL_GPL(llist_del_first);

This isn't needed for functionality correctness. Many users of llist ask for performance. So, it may be better to let the users to decide whether to set entry->next to NULL.

Ok, get it, thanks for your reply.

Signature · 2 lines
Best regards,
Li Qiang