Commit 5023bd7a804e09d0bf4937d8fecb5d85af6dba3c

Authored by Simon Glass
Committed by Bin Meng
1 parent b91c6a1209

list: Add list_last_entry() to find the last entry

We have list_first_entry() but in some cases it is useful to find the last
item added to the list. Add a macro for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Showing 1 changed file with 11 additions and 0 deletions Side-by-side Diff

include/linux/list.h
... ... @@ -338,6 +338,17 @@
338 338 list_entry((ptr)->next, type, member)
339 339  
340 340 /**
  341 + * list_last_entry - get the last element from a list
  342 + * @ptr: the list head to take the element from.
  343 + * @type: the type of the struct this is embedded in.
  344 + * @member: the name of the list_struct within the struct.
  345 + *
  346 + * Note, that list is expected to be not empty.
  347 + */
  348 +#define list_last_entry(ptr, type, member) \
  349 + list_entry((ptr)->prev, type, member)
  350 +
  351 +/**
341 352 * list_for_each - iterate over a list
342 353 * @pos: the &struct list_head to use as a loop cursor.
343 354 * @head: the head for your list.