From nobody Fri Sep 25 02:42:22 2026 Received: from mail-m16.yeah.net (mail-m16.yeah.net [1.95.21.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B1474BD377 for ; Thu, 17 Sep 2026 12:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=1.95.21.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649834; cv=none; b=K5gPNY8mdgMUL+BvEBAtGlMoLm+M0mxq1ik6Ec4y6sH3cYwUNg73FEspIE/o402L9JKnshAgYfLjPmdoqyYw0WPLYgXjZ0jxAxZpzxjaCbhce/+qDA4erhqVDWCCzLYwnvK7oDnEEZM1S2SEIH0c8TwV0QQRM7rghcjG8HJz/wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649834; c=relaxed/simple; bh=afLLov8+HOFjnVpN4kyARrrj11AlwaPGQMEWRQ+A5d8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uzXeaikCsfijfmpsUp40i8rv1xn/kBgXKNwIfzwx8WevPPCwPtT993GLSDhi2hlgWL2Aj7MqvQbqUudu11laaRHqWZdzlhF91Qlw9Hkklr7rtZYs1BW65TXr176PUsSyzzkotGLq1yVwBP8pNpKQmUY0xSdVXnm5JPbEEP0bKHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yeah.net; spf=pass smtp.mailfrom=yeah.net; dkim=pass (1024-bit key) header.d=yeah.net header.i=@yeah.net header.b=asXTqF6f; arc=none smtp.client-ip=1.95.21.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yeah.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yeah.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yeah.net header.i=@yeah.net header.b="asXTqF6f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=iB /ct50ZWCmIaRLVOTouf0UtbqUJgCxWBOwHAPKRSec=; b=asXTqF6f7IEwrPw45u ydwhNYOovPz94sLYC+SjqVycfTIZWL4b3QtQEARLmp4lZDYfW7IWRRyRGh66wFMN 9IRDqbVgx72IZNPkusq3Gvh7okHLSu6WFLtRLrCK+B5f7O0QejSzLbCDwIyCKFnJ e3pEqPCpefu38vaagHGgXXNYI= Received: from deepin (unknown []) by gzsmtp3 (Coremail) with UTF8SMTPA id M88vCgD3r5dQ46tqBSYYAA--.16246S3; Thu, 17 Sep 2026 20:55:47 +0800 (CST) From: Ziran Zhang To: Andy Shevchenko Cc: "Paul E . McKenney" , David Howells , Jonathan Corbet , Jordan R Abrahams-Whitehead , Marco Elver , Nilay Shroff , Edward Cree , Simona Vetter , linux-kernel@vger.kernel.org, Ziran Zhang Subject: [PATCH v2 1/2] list: add missing empty list check to list_cut_before() Date: Thu, 17 Sep 2026 20:55:04 +0800 Message-ID: <20260917125505.50897-2-zhangcoder@yeah.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260917125505.50897-1-zhangcoder@yeah.net> References: <20260917125505.50897-1-zhangcoder@yeah.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: M88vCgD3r5dQ46tqBSYYAA--.16246S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7XrW8Zr45tF1UCF1DtryrJFb_yoW3KFc_Z3 4IqwsxWr48Xr4qqw4IkF97Kr1fW3yxXF12grsaqw17AFyDCan0ka48uF1DJ3y5Wws3ur98 Aan5W3s7Wr15AjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: x2kd0wpfrgv2o61htxgoqh3/1tbiNhOSU2qr41M3HwAA39 Content-Type: text/plain; charset="utf-8" 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 =3D=3D entry case. Signed-off-by: Ziran Zhang --- 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 *l= ist, struct list_head *head, struct list_head *entry) { + if (list_empty(head)) { + INIT_LIST_HEAD(list); + return; + } + if (head->next =3D=3D entry) { INIT_LIST_HEAD(list); return; --=20 2.51.0 From nobody Fri Sep 25 02:42:22 2026 Received: from mail-m16.yeah.net (mail-m16.yeah.net [1.95.21.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D254FDE61 for ; Thu, 17 Sep 2026 12:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=1.95.21.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649845; cv=none; b=swsur9Mx7fkBpRSKBW13ooPtD8k36dLTBHJkuAFyqSs9bDTne8rXJaX+7L1wwuz12jqgtmZEsMGVmEvbRf4Oypv2Rk+rXlyTCU+KuRi2pJGOCvlwFjETfhvcmUhFLHu97VzumfNrv0X8YW0lewDvB/i9XnFl8xx1i98a0fuaPcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649845; c=relaxed/simple; bh=MASPkbQOt8+v5DhrINNpRpBC5fcOe7PFfzzz+xzhTtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CWnSIFfWpZJhYXaDgz1s/r37vt3zXlYn2/U8YE83JqB6VG9LCsoRMJO9WjEfqiWiSX0wKSOjqPhnEUHMUrVoHDqKfHnZBK/TqV0gpBBaht8wiEzbdnlIRwNPuiXFnA+f32WWhsaOEHil5FDv9a0DpLLup4PEkdSOII+RGFBq8xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yeah.net; spf=pass smtp.mailfrom=yeah.net; dkim=pass (1024-bit key) header.d=yeah.net header.i=@yeah.net header.b=qF61VdUJ; arc=none smtp.client-ip=1.95.21.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yeah.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yeah.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yeah.net header.i=@yeah.net header.b="qF61VdUJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Ah 3giLfJuk/TXnUarY/+RjA5PWAFHKErjJXcXmYpHp0=; b=qF61VdUJy0aurE7fK9 jXDAZfS8cf0tPORV5a/z9kRpoZg7joODLXvSzLPctxFao2vVrYfVZrDFoqYzG6jU Ll143KLBtlPC0bHrS/XVTdHAoK8nFRKgArsE5knJ7cF77RBDdT833gWDR/LHNlzm JfBoQ6NMSXQasbnKfstO2zz4k= Received: from deepin (unknown []) by gzsmtp3 (Coremail) with UTF8SMTPA id M88vCgD3r5dQ46tqBSYYAA--.16246S4; Thu, 17 Sep 2026 20:55:48 +0800 (CST) From: Ziran Zhang To: Andy Shevchenko Cc: "Paul E . McKenney" , David Howells , Jonathan Corbet , Jordan R Abrahams-Whitehead , Marco Elver , Nilay Shroff , Edward Cree , Simona Vetter , linux-kernel@vger.kernel.org, Ziran Zhang Subject: [PATCH v2 2/2] list: add KUnit test for list_cut_before() empty list case Date: Thu, 17 Sep 2026 20:55:05 +0800 Message-ID: <20260917125505.50897-3-zhangcoder@yeah.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260917125505.50897-1-zhangcoder@yeah.net> References: <20260917125505.50897-1-zhangcoder@yeah.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: M88vCgD3r5dQ46tqBSYYAA--.16246S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7uF1UXw13GFWkGr18Zr13Arb_yoW8XFW8pr 98Kr1vgFWUJF1Igw1xWFyxKrZavF4kJryj9ryfC3ykZFyUAa1UArnrGrWUZrn3XrW8ZFZ8 Za1DtF17Jw4DJFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUUUUUU= X-CM-SenderInfo: x2kd0wpfrgv2o61htxgoqh3/1tbiNxSTVGqr41Q3gAAA3l Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ziran Zhang Reviewed-by: Andy Shevchenko --- 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 *te= st) KUNIT_EXPECT_EQ(test, i, 3); } =20 +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[] =3D { 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), --=20 2.51.0