[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [RFC PATCH 01/19] xen/arm: add linked list apis



>>> On 02.03.15 at 13:30, <vijay.kilari@xxxxxxxxx> 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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.