[PATCH v3 1/2] list: add missing empty list check to list_cut_before()
From: Ziran Zhang
Date: Fri Sep 18 2026 - 04:16:05 EST
list_cut_before() lacks the list_empty() guard present in
list_cut_position(). With an empty head, the function falls through
to the pointer updates instead of returning early.
Both helpers share the same kernel-doc wording:
'You should pass on @entry an element you know is on @head.'
Nevertheless, list_cut_position() returns early for an empty head,
and list_splice() also checks its source list before doing any
pointer updates. Make list_cut_before() consistent with them for
the empty-list 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