[PATCH v2 1/2] list: add missing empty list check to list_cut_before()
From: Ziran Zhang
Date: Thu Sep 17 2026 - 09:27:44 EST
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@xxxxxxxx>
---
include/linux/list.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/list.h b/include/linux/list.h
index 77fb62f79..4d2061d35 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