Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp549142lqp; Wed, 12 Jun 2024 09:06:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCULFCwqE6uomo0mEjGK1YYD+cgad8EqC8TU6sQ/40g1RPWczQbr/KvlisdWCPrDD1TljUyxPtCRJyqTO9gJ700E3sKuts8U6fIEjaDMQw== X-Google-Smtp-Source: AGHT+IF8EXBB0FbPucMVR3A5WCk7a0HvXps+Y0jApt9qA5BKgp2kxdVjw6SFU3VzRg3MQjRcW9fW X-Received: by 2002:a05:6a00:1950:b0:6ed:21c0:986c with SMTP id d2e1a72fcca58-705bcef3aa3mr2850564b3a.24.1718208400111; Wed, 12 Jun 2024 09:06:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718208400; cv=pass; d=google.com; s=arc-20160816; b=msQIjX+CDHANXnJC6rgotYnJzPRqQ94SvMun7q8pHU3PJ255z4cQgIZdKcnqjs3cf6 hVOfBo9Lm96cp8T7WfhXYRZXK9NlCdxi6yWED4ARE9Ngnc8WZUq921J1vb1Nr5qN+adf wm6nsDJcY70q/dus/2WeI8gBCpPygCKnWbdMu3ewy8huYMWF3hwkvxgKvcr3O2CbZlBs gpW1SjgLUR7jcvjr0f3qeEhHNqEomovQcY4oF2V777k1XlEDo9IQ26J8LknYXOVx3Ev7 5GtUHn+yxIFz8j69xZuKMvHxI5vVbSt0P32Km6dS3IEuSYAyS+3EAyvu9sVUvJt4uerG lmew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=I/Z6N+8GhYKAY2oDMx40QxjDLD0DkKbXD3UysbN8DvI=; fh=xbRWc02XV7VItOH0DU0/7wig5o2Ry/HCLxAJe4b0KOk=; b=QoF+lZ1isLTjb2qyIlZuVOdAlmb0mwMgbzjTXI9WjUrDSwipQffHCVxn+wtE2kprJ2 8wkoH411uosX3KVBstFGoW0hGhktwoPkrJaloFisXBXW/+QgUdEa2AN4iCFUB+NlbEYy BlSVr8r//aLLJWriW58ajgQdrjCFa3h7XWa8aXUAXih1jXaJOjy+almMx01fB1B8xNRt 3CrzRm6VuMWoZcs6dlGKFAsq6NBm3cx+eC/Bpxz7G1w5L0jl7moqNmnxKgPFwNyLtr/e +1xHJQntVOkFP0oc+mwUwsCubwO6cqlyLezdoXKQiVgapSfbv59UyeMC/n5ncR9nV52M 3DnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=F59ldffT; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); spf=pass (google.com: domain of linux-kernel+bounces-211823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=meta.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70433739dadsi7068727b3a.220.2024.06.12.09.06.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 09:06:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=F59ldffT; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); spf=pass (google.com: domain of linux-kernel+bounces-211823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=meta.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 199DF28BE0F for ; Wed, 12 Jun 2024 15:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C3E2180A97; Wed, 12 Jun 2024 15:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="F59ldffT" Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 497D817FAB7 for ; Wed, 12 Jun 2024 15:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718207524; cv=none; b=iNbYpmlYrMi/LlDjIEBz10qoKpQGrxFeFArWyNrIAedMqmPFacTDV+7qPrzXtXfIbeeCbx0QgA6Dxo1obD9Fi7r0sHejC+ImltXokL+CkDl3KgDN1/G5o0TfB3xdCi4BFvY7S5HCpKzKrqn5q+rspjYlXBZ7tteKNrsNvo+P+uY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718207524; c=relaxed/simple; bh=xtBDFoQmM9KRsbYQrWoWhaDcGs4A5YynZBYJRZNzOfE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GI9HuQotOq7eG05TWDjELcb5mg6V2hfrWmVKNtOebUNMT8dmGT/KVLxkCblEUDc9WdwYgYrjnVtWJxyCj4pU/fMdx+1mGT5+mVJwPQ2ROKYCzJfJlOus8Ksu801jRlqQY2NeKmkLqYa+nL6ahGVOU4G/z61AWdke9WCufQjQcOU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=F59ldffT; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 45CFFKZc007498 for ; Wed, 12 Jun 2024 08:52:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc : content-transfer-encoding : content-type : date : from : message-id : mime-version : subject : to; s=s2048-2021-q4; bh=I/Z6N+8GhYKAY2oDMx40QxjDLD0DkKbXD3UysbN8DvI=; b=F59ldffTNBenHKBhWMmTrYlfiDKpxNy/YcsE8FHZ5mJ0eHqKohUX/2S2n7gIHsLnH/XY v+tu7vrRbT7Aqa37QzcPu1YSLrCxyb3ZdPtvtEzhLkmwhlDiInTeL9MfAXXJSUFgOIyL M5pChy1VRE+yWbwWshmtr1yPfFi0tF/Bzw92PCu6zleAbq8FVyqHyv7gAT+FUiRFBjmn JMv9Px6Nhvy9x4Gy7Ir+7nq/Cv+pvkffzWKS8R0FuxVCwXO8+6rpy8H4Go6HF8TAz4/X hKiODwIj5mLIuvXGYsiCCPLYqM2HLjQHL+13lWsi0Jc+Ttwu4JPnvof7m7Ibc2hNE6hS Vw== Received: from mail.thefacebook.com ([163.114.134.2]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3yphwwak9h-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 12 Jun 2024 08:52:02 -0700 Received: from twshared15118.35.frc1.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Wed, 12 Jun 2024 15:51:58 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id DCB8BF5EA644; Wed, 12 Jun 2024 08:51:47 -0700 (PDT) From: Keith Busch To: , , CC: , , , , , , Keith Busch Subject: [PATCH 1/2] list: introduce a new cutting helper Date: Wed, 12 Jun 2024 08:51:34 -0700 Message-ID: <20240612155135.3060667-1-kbusch@meta.com> X-Mailer: git-send-email 2.43.0 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-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: OwlQJr-qOc0LM7j4N2j5vuUeS4WkBg74 X-Proofpoint-GUID: OwlQJr-qOc0LM7j4N2j5vuUeS4WkBg74 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-12_08,2024-06-12_02,2024-05-17_01 From: Keith Busch Provide a helper to remove elements from a list to the end, and place those elements in a new list. Signed-off-by: Keith Busch --- include/linux/list.h | 20 ++++++++++++++++++++ lib/list-test.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 5f4b0a39cf46a..f22850e854820 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -520,6 +520,26 @@ static inline void list_cut_before(struct list_head = *list, entry->prev =3D head; } =20 +/** + * list_cut - cut a list into two from the entry + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * + * This helper removes elements from @head starting at @entry until the = end, + * and appends them to @lists. + */ +static inline void list_cut(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + list->next =3D entry; + list->prev =3D head->prev; + head->prev =3D entry->prev; + entry->prev->next =3D head; + entry->prev =3D list; + list->prev->next =3D list; +} + static inline void __list_splice(const struct list_head *list, struct list_head *prev, struct list_head *next) diff --git a/lib/list-test.c b/lib/list-test.c index 0cc27de9cec88..1507f46cf1ade 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -382,6 +382,34 @@ static void list_test_list_is_singular(struct kunit = *test) KUNIT_EXPECT_FALSE(test, list_is_singular(&list)); } =20 +static void list_test_list_cut(struct kunit *test) +{ + struct list_head entries[3], *cur; + LIST_HEAD(list1); + LIST_HEAD(list2); + int i =3D 0; + + list_add_tail(&entries[0], &list1); + list_add_tail(&entries[1], &list1); + list_add_tail(&entries[2], &list1); + + /* before: [list1] -> entries[0] -> entries[1] -> entries[2] */ + list_cut(&list2, &list1, &entries[1]); + /* after: [list1] -> entries[0], [list2] -> entries[1] -> entries[2] */ + + list_for_each(cur, &list1) { + KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]); + i++; + } + + KUNIT_EXPECT_EQ(test, i, 1); + + list_for_each(cur, &list2) { + KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]); + i++; + } +} + static void list_test_list_cut_position(struct kunit *test) { struct list_head entries[3], *cur; @@ -780,6 +808,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), KUNIT_CASE(list_test_list_splice), KUNIT_CASE(list_test_list_splice_tail), KUNIT_CASE(list_test_list_splice_init), --=20 2.43.0