From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com ([141.146.126.78]:42380 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726414AbfFXOyG (ORCPT ); Mon, 24 Jun 2019 10:54:06 -0400 Date: Mon, 24 Jun 2019 07:53:25 -0700 From: "Darrick J. Wong" Subject: Re: [PATCH 01/12] list.h: add a list_pop helper Message-ID: <20190624145325.GF5387@magnolia> References: <20190624055253.31183-1-hch@lst.de> <20190624055253.31183-2-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190624055253.31183-2-hch@lst.de> Sender: linux-xfs-owner@vger.kernel.org List-ID: List-Id: xfs To: Christoph Hellwig Cc: Damien Le Moal , Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org On Mon, Jun 24, 2019 at 07:52:42AM +0200, Christoph Hellwig wrote: > We have a very common pattern where we want to delete the first entry > from a list and return it as the properly typed container structure. > > Add a list_pop helper to implement this behavior. > > Signed-off-by: Christoph Hellwig > --- > include/linux/list.h | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/include/linux/list.h b/include/linux/list.h > index e951228db4b2..e07a5f54cc9d 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -500,6 +500,28 @@ static inline void list_splice_tail_init(struct list_head *list, > pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ > }) > > +/** > + * list_pop - delete the first entry from a list and return it > + * @list: the list to take the element from. > + * @type: the type of the struct this is embedded in. > + * @member: the name of the list_head within the struct. > + * > + * Note that if the list is empty, it returns NULL. > + */ > +#define list_pop(list, type, member) \ Unnecessary space after the ')' here, though I can fix that up if I merge this version of the series... Reviewed-by: Darrick J. Wong --D > +({ \ > + struct list_head *head__ = (list); \ > + struct list_head *pos__ = READ_ONCE(head__->next); \ > + type *entry__ = NULL; \ > + \ > + if (pos__ != head__) { \ > + entry__ = list_entry(pos__, type, member); \ > + list_del(pos__); \ > + } \ > + \ > + entry__; \ > +}) > + > /** > * list_next_entry - get the next element in list > * @pos: the type * to cursor > -- > 2.20.1 >