From nobody Fri Sep 25 01:19:13 2026 Received: from mail-m16.yeah.net (mail-m16.yeah.net [220.197.32.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 113B94A2041 for ; Fri, 18 Sep 2026 08:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.32.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789719206; cv=none; b=U4XEPp6MIXZQKcOie1GgpKbnZ6BdXkaV0uIv/LdkmNvG8/VPFkmYVU01mJZH3oZ51rq4qU1PBYQzZFurkWQWzgMbSmnCcAFsaEzVMcZMcj6cRPCHFz5k1RojfL12izbPKlyKomlhM+0AyWbni+8x0UmUlNci2b9w5q0ZmOhZqDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789719206; c=relaxed/simple; bh=TYPo0AjC92sG4ibISh77MqvxgMsC3vuvbr4a0Ovm+IU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NT3ajZzL+IGTviH0Cqpa6fuN1VUOhJnXgEqU3no5RSMf4JMYc9skwgeNMyVkU0MPO7ZXIL/vpa/iX9H80FfmVYMr9fQkzFf2JtbufDvuIg9iZo8w7oZA3ETEa5ekrKj3HpzaQWXOUQcI2wYTe5DkSLGXBRpz30zuvZkNyPuWHnM= 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=FwnTF1jw; arc=none smtp.client-ip=220.197.32.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="FwnTF1jw" 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=xj 8oew8uzkbXr8SWDpsY9XwnrDU4b1027og5au+USQQ=; b=FwnTF1jwk74ewJ/t/f eW0+yKDjYdU7ZyI7Lw3oPxJKUEABz0/9M1hjd1IDfFe+I3+bQ46E4AXx2U5QavGL bu6A7QvPw+j667gMUtppIbGl1yCWsIaTgzjP1wvhT0djM+BPcv7twKjA/7Dnz81t HIY4Zi6rwLIQNNGPQQDSznV3k= Received: from deepin (unknown []) by gzsmtp3 (Coremail) with UTF8SMTPA id M88vCgD3P5cQ8qxqHkUlAA--.61508S3; Fri, 18 Sep 2026 16:11:03 +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 v3 1/2] list: add missing empty list check to list_cut_before() Date: Fri, 18 Sep 2026 16:10:25 +0800 Message-ID: <20260918081026.8050-2-zhangcoder@yeah.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260918081026.8050-1-zhangcoder@yeah.net> References: <20260918081026.8050-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: M88vCgD3P5cQ8qxqHkUlAA--.61508S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7XrW8Zr4rXryxtrW5JrWxtFb_yoWDKrX_Z3 s7Xrs8Gr4UXrs8tr4IkFZ7KrySgw4xXFn7Wrsaqw17ZFyDGFs0va4xZ3ZrJ3yfWrZ3Wr98 Aan5ur929r13ZjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: x2kd0wpfrgv2o61htxgoqh3/1tbiIheHSGqs8hcEbgAA3z Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Andy Shevchenko --- 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 01:19:13 2026 Received: from mail-m16.yeah.net (mail-m16.yeah.net [1.95.21.17]) (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 7BAFD39B4A5 for ; Fri, 18 Sep 2026 08:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=1.95.21.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789719186; cv=none; b=M5qLFOKYFb22g7zeCbi8PoOhvAe3vZ5LxP1Js6Efd3+q3Ew6ZPOK8hgVgAHybd33wRO1aKJcH0plunZqg/wR69OMk4EqcXBYWrnnHMEgY1OcYRib+3z5vOpskLKB7MbYj4j+bCm6e2XLtPzjJLsKQtsMOE/Rv6S8Ok34ppyopWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789719186; c=relaxed/simple; bh=AA7Woc91+PRuZ1C/psObSUA6bs8HRfLq850FynxWm1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z63Bqa33eiHNUb0QkuCEmRXF2/vqsBiQp+aTowOPU1TIV0iTiW6ioeMEzc/sbjfDJ9B4jdn8SI4RTV2bImz52vNH4/QH+ZbKeLNGIEcRB93H+J5DEFL5b+ocshzlLIQ8qzegV36ppXH1Stv7LciwENS/yuY+cKyAXzmmwNLSt9s= 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=KgsLg1gy; arc=none smtp.client-ip=1.95.21.17 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="KgsLg1gy" 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=UI 55jaVKKZuklPx4MeKfm/62j3yFw1VnDSH+x//D7TU=; b=KgsLg1gybvfQA+g5FM XA1GND1UI+NXb6PDn1Ffmsl8a7JukW3zeI6Vdl2yUByNMi3YB7Ij20vbHVfxhKLD XK3syTNVgt8onpLctA4O6HLEiUccml9FI3XYpjk9ER3DhWHpSXqj9zmrMGqj40fF X3kwgZCJDw7fcudF1K6zl7Fa0= Received: from deepin (unknown []) by gzsmtp3 (Coremail) with UTF8SMTPA id M88vCgD3P5cQ8qxqHkUlAA--.61508S4; Fri, 18 Sep 2026 16:11:05 +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 v3 2/2] list: add KUnit test for list_cut_before() empty list case Date: Fri, 18 Sep 2026 16:10:26 +0800 Message-ID: <20260918081026.8050-3-zhangcoder@yeah.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260918081026.8050-1-zhangcoder@yeah.net> References: <20260918081026.8050-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: M88vCgD3P5cQ8qxqHkUlAA--.61508S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7uF1UXw13GFWkGr18Zr13Arb_yoW8WrW5pr 98Kr1vgFW8JF1Igw1xXFyxKrZavF4kJryj9ryxC397ZryUAa1UArnrGrWUArn3XrW8ZFZ8 Za1UtF47Gw4DJFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUUUUUU= X-CM-SenderInfo: x2kd0wpfrgv2o61htxgoqh3/1tbiIhmISWqs8hkEeAAA3r 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. Reviewed-by: Andy Shevchenko Signed-off-by: Ziran Zhang --- 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