diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2013-10-27 14:58:09 +0100 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2013-10-27 18:38:25 +0100 |
commit | 3db1becf5420fa80e27386390ec36896dd50015d (patch) | |
tree | 73e6c742a18bf4c22a5a72ae817f488ab605c3c2 | |
parent | bff97930ee6b5cdc01519081c3ff88dffffb9ecb (diff) |
backports: add list_first_entry_or_null
This was added in the following upstream commit:
commit 6d7581e62f8be462440d7b22c6361f7c9fa4902b
Author: Jiri Pirko <jiri@resnulli.us>
Date: Wed May 29 05:02:56 2013 +0000
list: introduce list_first_entry_or_null
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r-- | backport/backport-include/linux/list.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/backport/backport-include/linux/list.h b/backport/backport-include/linux/list.h index fb5ee4b9..38355952 100644 --- a/backport/backport-include/linux/list.h +++ b/backport/backport-include/linux/list.h @@ -115,4 +115,17 @@ static inline void list_splice_tail_init(struct list_head *list, } #endif +#ifndef list_first_entry_or_null +/** + * 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) +#endif /* list_first_entry_or_null */ + #endif /* __BACKPORT_LIST_H */ |