* [PATCH v4 0/2] list: add missing empty list check to list_cut_before()
@ 2026-11-30 3:22 Ziran Zhang
2026-11-30 3:22 ` [PATCH v4 1/2] " Ziran Zhang
2026-11-30 3:22 ` [PATCH v4 2/2] list: add KUnit test for list_cut_before() empty list case Ziran Zhang
0 siblings, 2 replies; 5+ messages in thread
From: Ziran Zhang @ 2026-11-30 3:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, David Gow, Paul E . McKenney, David Howells,
Jonathan Corbet, Jordan R Abrahams-Whitehead, Marco Elver,
Nilay Shroff, Edward Cree, Simona Vetter, linux-kernel,
Ziran Zhang
Patch 1 adds the missing list_empty() guard; patch 2 adds a KUnit
test case.
v4:
- Add Reviewed-by from Andy Shevchenko to patch 1/2.
- Add Acked-by from David Gow to patch 2/2.
v3:
- Elaborate the rationale in the commit message, as requested
by Andy Shevchenko.
- Add Reviewed-by from Andy Shevchenko to patch 2/2.
v2:
- Add a KUnit test case as requested by Andy Shevchenko.
- Patch 1 adds the missing list_empty() guard, patch 2 adds the
test case.
v1:
- https://lore.kernel.org/all/20260916100001.10634-1-zhangcoder@yeah.net/
Tested with:
tools/testing/kunit/kunit.py run --kernel_args=kunit.filter_glob='list-kunit-test'
Test result:
[PASSED] list_test_list_cut_before_empty
Testing complete. Ran 40 tests: passed: 40
Ziran Zhang (2):
list: add missing empty list check to list_cut_before()
list: add KUnit test for list_cut_before() empty list case
include/linux/list.h | 5 +++++
lib/tests/list-test.c | 18 ++++++++++++++++++
2 files changed, 23 insertions(+)
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] list: add missing empty list check to list_cut_before()
2026-11-30 3:22 [PATCH v4 0/2] list: add missing empty list check to list_cut_before() Ziran Zhang
@ 2026-11-30 3:22 ` Ziran Zhang
2026-12-01 1:40 ` + list-add-missing-empty-list-check-to-list_cut_before.patch added to mm-nonmm-unstable branch Andrew Morton
2026-11-30 3:22 ` [PATCH v4 2/2] list: add KUnit test for list_cut_before() empty list case Ziran Zhang
1 sibling, 1 reply; 5+ messages in thread
From: Ziran Zhang @ 2026-11-30 3:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, David Gow, Paul E . McKenney, David Howells,
Jonathan Corbet, Jordan R Abrahams-Whitehead, Marco Elver,
Nilay Shroff, Edward Cree, Simona Vetter, linux-kernel,
Ziran Zhang
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.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
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 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] list: add KUnit test for list_cut_before() empty list case
2026-11-30 3:22 [PATCH v4 0/2] list: add missing empty list check to list_cut_before() Ziran Zhang
2026-11-30 3:22 ` [PATCH v4 1/2] " Ziran Zhang
@ 2026-11-30 3:22 ` Ziran Zhang
2026-12-01 1:40 ` + list-add-kunit-test-for-list_cut_before-empty-list-case.patch added to mm-nonmm-unstable branch Andrew Morton
1 sibling, 1 reply; 5+ messages in thread
From: Ziran Zhang @ 2026-11-30 3:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, David Gow, Paul E . McKenney, David Howells,
Jonathan Corbet, Jordan R Abrahams-Whitehead, Marco Elver,
Nilay Shroff, Edward Cree, Simona Vetter, linux-kernel,
Ziran Zhang
Add a test case covering list_cut_before() with an empty head
and an entry not on the list. Without the empty list guard,
the call would corrupt the head list.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: David Gow <david@davidgow.net>
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
lib/tests/list-test.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/tests/list-test.c b/lib/tests/list-test.c
index 6d9227a2b..f54facdb7 100644
--- a/lib/tests/list-test.c
+++ b/lib/tests/list-test.c
@@ -446,6 +446,23 @@ static void list_test_list_cut_before(struct kunit *test)
KUNIT_EXPECT_EQ(test, i, 3);
}
+static void list_test_list_cut_before_empty(struct kunit *test)
+{
+ LIST_HEAD(entry);
+ LIST_HEAD(head);
+ LIST_HEAD(list);
+
+ /*
+ * entry is initialized but not on head. With an empty head
+ * this used to corrupt the list.
+ */
+ list_cut_before(&list, &head, &entry);
+
+ KUNIT_EXPECT_TRUE(test, list_empty(&head));
+ KUNIT_EXPECT_TRUE(test, list_empty(&list));
+ KUNIT_EXPECT_TRUE(test, list_empty(&entry));
+}
+
static void list_test_list_splice(struct kunit *test)
{
struct list_head entries[5], *cur;
@@ -788,6 +805,7 @@ static struct kunit_case list_test_cases[] = {
KUNIT_CASE(list_test_list_is_singular),
KUNIT_CASE(list_test_list_cut_position),
KUNIT_CASE(list_test_list_cut_before),
+ KUNIT_CASE(list_test_list_cut_before_empty),
KUNIT_CASE(list_test_list_splice),
KUNIT_CASE(list_test_list_splice_tail),
KUNIT_CASE(list_test_list_splice_init),
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* + list-add-missing-empty-list-check-to-list_cut_before.patch added to mm-nonmm-unstable branch
2026-11-30 3:22 ` [PATCH v4 1/2] " Ziran Zhang
@ 2026-12-01 1:40 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-12-01 1:40 UTC (permalink / raw)
To: mm-commits, simona.vetter, paulmck, nilay, elver, ecree, dhowells,
david, corbet, andriy.shevchenko, ajordanr, zhangcoder, akpm
The patch titled
Subject: list: add missing empty list check to list_cut_before()
has been added to the -mm mm-nonmm-unstable branch. Its filename is
list-add-missing-empty-list-check-to-list_cut_before.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/list-add-missing-empty-list-check-to-list_cut_before.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Ziran Zhang <zhangcoder@yeah.net>
Subject: list: add missing empty list check to list_cut_before()
Date: Mon, 30 Nov 2026 11:22:23 +0800
Patch series "list: add missing empty list check to list_cut_before()", v4.
Patch 1 adds the missing list_empty() guard; patch 2 adds a KUnit
test case.
This patch (of 2):
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.
Link: https://lore.kernel.org/20261130032224.15372-1-zhangcoder@yeah.net
Link: https://patch.msgid.link/20261130032224.15372-2-zhangcoder@yeah.net
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: David Gow <david@davidgow.net>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Jordan R Abrahams-Whitehead <ajordanr@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Nilay Shroff <nilay@linux.ibm.com>
Cc: Edward Cree <ecree@solarflare.com>
Cc: Simona Vetter <simona.vetter@ffwll.ch>
include/linux/list.h | 5 +++++
1 file changed, 5 insertions(+)
--- a/include/linux/list.h~list-add-missing-empty-list-check-to-list_cut_before
+++ a/include/linux/list.h
@@ -555,6 +555,11 @@ static inline void list_cut_before(struc
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;
_
Patches currently in -mm which might be from zhangcoder@yeah.net are
include-linux-jhashh-fix-kernel-doc-parameter-name.patch
list-add-missing-empty-list-check-to-list_cut_before.patch
list-add-kunit-test-for-list_cut_before-empty-list-case.patch
^ permalink raw reply [flat|nested] 5+ messages in thread
* + list-add-kunit-test-for-list_cut_before-empty-list-case.patch added to mm-nonmm-unstable branch
2026-11-30 3:22 ` [PATCH v4 2/2] list: add KUnit test for list_cut_before() empty list case Ziran Zhang
@ 2026-12-01 1:40 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-12-01 1:40 UTC (permalink / raw)
To: mm-commits, simona.vetter, paulmck, nilay, elver, ecree, dhowells,
david, corbet, andriy.shevchenko, ajordanr, zhangcoder, akpm
The patch titled
Subject: list: add KUnit test for list_cut_before() empty list case
has been added to the -mm mm-nonmm-unstable branch. Its filename is
list-add-kunit-test-for-list_cut_before-empty-list-case.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/list-add-kunit-test-for-list_cut_before-empty-list-case.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Ziran Zhang <zhangcoder@yeah.net>
Subject: list: add KUnit test for list_cut_before() empty list case
Date: Mon, 30 Nov 2026 11:22:24 +0800
Add a test case covering list_cut_before() with an empty head
and an entry not on the list. Without the empty list guard,
the call would corrupt the head list.
Link: https://patch.msgid.link/20261130032224.15372-3-zhangcoder@yeah.net
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: David Gow <david@davidgow.net>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Jordan R Abrahams-Whitehead <ajordanr@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Nilay Shroff <nilay@linux.ibm.com>
Cc: Edward Cree <ecree@solarflare.com>
Cc: Simona Vetter <simona.vetter@ffwll.ch>
lib/tests/list-test.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
--- a/lib/tests/list-test.c~list-add-kunit-test-for-list_cut_before-empty-list-case
+++ a/lib/tests/list-test.c
@@ -446,6 +446,23 @@ static void list_test_list_cut_before(st
KUNIT_EXPECT_EQ(test, i, 3);
}
+static void list_test_list_cut_before_empty(struct kunit *test)
+{
+ LIST_HEAD(entry);
+ LIST_HEAD(head);
+ LIST_HEAD(list);
+
+ /*
+ * entry is initialized but not on head. With an empty head
+ * this used to corrupt the list.
+ */
+ list_cut_before(&list, &head, &entry);
+
+ KUNIT_EXPECT_TRUE(test, list_empty(&head));
+ KUNIT_EXPECT_TRUE(test, list_empty(&list));
+ KUNIT_EXPECT_TRUE(test, list_empty(&entry));
+}
+
static void list_test_list_splice(struct kunit *test)
{
struct list_head entries[5], *cur;
@@ -788,6 +805,7 @@ static struct kunit_case list_test_cases
KUNIT_CASE(list_test_list_is_singular),
KUNIT_CASE(list_test_list_cut_position),
KUNIT_CASE(list_test_list_cut_before),
+ KUNIT_CASE(list_test_list_cut_before_empty),
KUNIT_CASE(list_test_list_splice),
KUNIT_CASE(list_test_list_splice_tail),
KUNIT_CASE(list_test_list_splice_init),
_
Patches currently in -mm which might be from zhangcoder@yeah.net are
include-linux-jhashh-fix-kernel-doc-parameter-name.patch
list-add-missing-empty-list-check-to-list_cut_before.patch
list-add-kunit-test-for-list_cut_before-empty-list-case.patch
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 1:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 3:22 [PATCH v4 0/2] list: add missing empty list check to list_cut_before() Ziran Zhang
2026-11-30 3:22 ` [PATCH v4 1/2] " Ziran Zhang
2026-12-01 1:40 ` + list-add-missing-empty-list-check-to-list_cut_before.patch added to mm-nonmm-unstable branch Andrew Morton
2026-11-30 3:22 ` [PATCH v4 2/2] list: add KUnit test for list_cut_before() empty list case Ziran Zhang
2026-12-01 1:40 ` + list-add-kunit-test-for-list_cut_before-empty-list-case.patch added to mm-nonmm-unstable branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.