mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] list: add missing empty list check to list_cut_before()
@ 2026-09-16 10:00 Ziran Zhang
  2026-09-16 10:53 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Ziran Zhang @ 2026-09-16 10:00 UTC (permalink / raw)
  To: Paul E . McKenney, David Howells, Jonathan Corbet,
	Jordan R Abrahams-Whitehead, Marco Elver, Nilay Shroff,
	Edward Cree, Andy Shevchenko, Simona Vetter
  Cc: linux-kernel, Ziran Zhang

list_cut_before() lacks the list_empty() guard present
in list_cut_position().

With an empty head and an entry not on the list, it
corrupts the list.

Add the missing check.  When head is empty, initialize
@list as empty, consistent with the existing
head->next == entry case.

Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
 include/linux/list.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index 77fb62f79928..4d2061d35beb 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -555,6 +555,11 @@ static inline void list_cut_before(struct list_head *list,
 				   struct list_head *head,
 				   struct list_head *entry)
 {
+	if (list_empty(head)) {
+		INIT_LIST_HEAD(list);
+		return;
+	}
+
 	if (head->next == entry) {
 		INIT_LIST_HEAD(list);
 		return;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-16 15:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 10:00 [PATCH] list: add missing empty list check to list_cut_before() Ziran Zhang
2026-09-16 10:53 ` Andy Shevchenko
2026-09-16 11:11   ` Ziran Zhang
2026-09-16 15:37     ` Andy Shevchenko
2026-09-16 15:52       ` Ziran Zhang

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®