mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ziran Zhang <zhangcoder@yeah.net>
To: "Paul E . McKenney" <paulmck@kernel.org>,
	David Howells <dhowells@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Jordan R Abrahams-Whitehead <ajordanr@google.com>,
	Marco Elver <elver@google.com>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Edward Cree <ecree@solarflare.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Simona Vetter <simona.vetter@ffwll.ch>
Cc: linux-kernel@vger.kernel.org, Ziran Zhang <zhangcoder@yeah.net>
Subject: [PATCH] list: add missing empty list check to list_cut_before()
Date: Wed, 16 Sep 2026 18:00:01 +0800	[thread overview]
Message-ID: <20260916100001.10634-1-zhangcoder@yeah.net> (raw)

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


             reply	other threads:[~2026-09-16 10:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 10:00 Ziran Zhang [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916100001.10634-1-zhangcoder@yeah.net \
    --to=zhangcoder@yeah.net \
    --cc=ajordanr@google.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=ecree@solarflare.com \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nilay@linux.ibm.com \
    --cc=paulmck@kernel.org \
    --cc=simona.vetter@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®