Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp165089rda; Sat, 21 Oct 2023 03:02:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw7nSqakb1EOxdKYWgQiDQ+fZC9EOiK8Ih8pBYCMbyK3Okgxt9T74EIC0+HnHngwHcaarC X-Received: by 2002:a17:902:cec8:b0:1ca:b820:74ed with SMTP id d8-20020a170902cec800b001cab82074edmr4571735plg.14.1697882538087; Sat, 21 Oct 2023 03:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697882538; cv=none; d=google.com; s=arc-20160816; b=0fXCrxi6Kn4fqbSUUB41Zjk24OzLY6scJ8ypryrTssYqxwMjj5ESMGXQ6FxOx9gyng 8djQsZvNwv4rGzPNreuLoUVN9ThdODAO7c7yFfXnZiuk3ipoUJPcpq048v4UBzww9urE 3zqWtWwkSWT3P2kcMsdy9dTtqm38zNY4iEMx9yUjAZlpy/iG6tr9jO+26A0SvLJKxwuy AXRJuo1E1OnRfT7H8LdYbaKnanPbdB8/b0GLQ/emTtgNc23kBo5KlGQsk4YO4nI46Dzh CPMH6TNhSccKmpwjzPSbWQLIlXHjRJOYxPKZMxL1eRsJfho2sif38B39K8Ic4ZRzbz2l EFQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=DHQCtmR3PiDk1ocQ2Km61SSv89cPPETSOoUQnd/MLQE=; fh=x4lAYWh3C3r34OLN2/RtvFURWlzVI7FtKSTT5mW7v/I=; b=j1gtzMsP6DSxlGqRuwX+5/MwLLEbNme9/Nk2MOm4KkwODNbOC01vcI+vI7OTeGOnn8 /Q05bpzZfFbXPcmPm69lCqBEP0YG0865pq26O1rA5KT4pQ54p5eM3uju+YKRWCyhqx30 Qd/qfIKn7YKev1SmTcW6Tas4/TcwR1P4n2JLDaETp385sM6bScd3Brh4wXVjOSvGgcNE Q0QEJWV+/mI82aLRAp4bYq3OxCpkVQUcosk3wqpmBxT5pKHEhC1KGA4l2x4HGb7I/hFB 55H1nxSdxX4A5eC6r1zEohm1fvuTQJ/Ix4u09AuPyv2BcmndQooeBHrxINw8jaWRldsU uw1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id jb22-20020a170903259600b001bbe13e753esi3073270plb.310.2023.10.21.03.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 03:02:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E8587807C5C5; Sat, 21 Oct 2023 03:00:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjJUKAH convert rfc822-to-8bit (ORCPT + 99 others); Sat, 21 Oct 2023 06:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbjJUKAF (ORCPT ); Sat, 21 Oct 2023 06:00:05 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4DB71A4 for ; Sat, 21 Oct 2023 03:00:03 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-311-BFirYQlCNs6HGOUkj5FRTQ-1; Sat, 21 Oct 2023 11:00:00 +0100 X-MC-Unique: BFirYQlCNs6HGOUkj5FRTQ-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 21 Oct 2023 10:59:59 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sat, 21 Oct 2023 10:59:59 +0100 From: David Laight To: 'Miklos Szeredi' , "linux-kernel@vger.kernel.org" CC: Linus Torvalds , Takashi Iwai , Mauro Carvalho Chehab , "Greg Kroah-Hartman" , Jakub Kicinski , Paolo Abeni , Al Viro , "Christian Brauner" , James Bottomley Subject: RE: [RFC PATCH 1/2] add list_for_each_entry_del() Thread-Topic: [RFC PATCH 1/2] add list_for_each_entry_del() Thread-Index: AQHaA0BhVdxwGOC7H06bkVWqGZ+tgrBUAoSg Date: Sat, 21 Oct 2023 09:59:59 +0000 Message-ID: <3ab474953c734d0bbf0177bf5d208799@AcuMS.aculab.com> References: <20231020102901.3354273-1-mszeredi@redhat.com> <20231020102901.3354273-2-mszeredi@redhat.com> In-Reply-To: <20231020102901.3354273-2-mszeredi@redhat.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 21 Oct 2023 03:00:17 -0700 (PDT) From: Miklos Szeredi > Sent: 20 October 2023 11:29 > > Add a new list iteration macro that always takes the first element of the > list and removes it, until the list is empty. ... > +/** > + * list_for_each_entry_del - iterate list and remove elements > + * @pos: the type * to use as a loop cursor. > + * @head: the head for your list. > + * @member: the name of the list_head within the struct. > + * > + * Delete first element from list before the iteration. Iterate until > + * the list is empty. > + */ > +#define list_for_each_entry_del(pos, head, member) \ > + while (!list_empty(head) && \ > + ({ pos = list_first_entry(head, typeof(*(pos)), member);\ > + list_del(&(pos)->member); 1; })) That pattern is actually pretty obvious. Add another wrapper and people end up having to read the header to find out what it does. I can't help feeling that if you look inside list_empty(), list_first_entry() and list_del() there is a lot of replicated code and tests. Adding a list_del_first() function that returns the deleted item or NULL to optimise it might make more sense. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)