From: "Jan Beulich" Subject: Re: [RFC PATCH 01/19] xen/arm: add linked list apis Date: Mon, 02 Mar 2015 13:21:39 +0000 Message-ID: <54F471F30200007800065084@mail.emea.novell.com> References: <1425299435-3278-1-git-send-email-vijay.kilari@gmail.com> <1425299435-3278-2-git-send-email-vijay.kilari@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1425299435-3278-2-git-send-email-vijay.kilari@gmail.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: vijay.kilari@gmail.com Cc: Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, Prasun.Kapoor@caviumnetworks.com, manish.jaggi@caviumnetworks.com, julien.grall@linaro.org, tim@xen.org, xen-devel@lists.xen.org, stefano.stabellini@citrix.com, Vijaya Kumar K List-Id: xen-devel@lists.xenproject.org >>> On 02.03.15 at 13:30, wrote: > --- a/xen/include/xen/list.h > +++ b/xen/include/xen/list.h > @@ -385,6 +385,39 @@ static inline void list_splice_init(struct list_head *list, > container_of(ptr, type, member) > > /** > + * list_first_entry - get the first element from a list > + * @ptr: the list head to take the element from. > + * @type: the type of the struct this is embedded in. > + * @member: the name of the list_struct within the struct. > + * > + * Note, that list is expected to be not empty. > + */ > +#define list_first_entry(ptr, type, member) \ > + list_entry((ptr)->next, type, member) > + > +/** > + * list_last_entry - get the last element from a list > + * @ptr: the list head to take the element from. > + * @type: the type of the struct this is embedded in. > + * @member: the name of the list_struct within the struct. > + * > + * Note, that list is expected to be not empty. > + */ > +#define list_last_entry(ptr, type, member) \ > + list_entry((ptr)->prev, type, member) Imo a patch like this should at least replace trivially obvious open coded variants of the newly added accessors, like page_list_first() and page_list_last() in xen/mm.h. Which then would make obvious that you should also be adding list_next_entry() and list_prev_entry(). > +/** > + * list_first_entry_or_null - get the first element from a list > + * @ptr: the list head to take the element from. > + * @type: the type of the struct this is embedded in. > + * @member: the name of the list_struct within the struct. > + * > + * Note that if the list is empty, it returns NULL. > + */ > +#define list_first_entry_or_null(ptr, type, member) \ > + (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) Even if not present in Linux, I think this should be augmented by list_last_entry_or_null(). Jan