diff options
author | Dominik Sliwa <dominik.sliwa@toradex.com> | 2017-07-02 16:41:37 +0200 |
---|---|---|
committer | Dominik Sliwa <dominik.sliwa@toradex.com> | 2017-07-02 16:41:37 +0200 |
commit | 52409fae3e4b8d16b68b61902fc09075cd97b75d (patch) | |
tree | e67110145c5843b3f199d872ae285e2546c9ebe2 /backport-include/linux/list.h |
Backports generated from 4.11 kernel
Initial commit.
Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.com>
Diffstat (limited to 'backport-include/linux/list.h')
-rw-r--r-- | backport-include/linux/list.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/backport-include/linux/list.h b/backport-include/linux/list.h new file mode 100644 index 0000000..13ab976 --- /dev/null +++ b/backport-include/linux/list.h @@ -0,0 +1,91 @@ +#ifndef __BACKPORT_LIST_H +#define __BACKPORT_LIST_H +#include_next <linux/list.h> +#include <linux/version.h> + +#if LINUX_VERSION_IS_LESS(3,9,0) +/** + * backport: + * + * commit 0bbacca7c3911451cea923b0ad6389d58e3d9ce9 + * Author: Sasha Levin <sasha.levin@oracle.com> + * Date: Thu Feb 7 12:32:18 2013 +1100 + * + * hlist: drop the node parameter from iterators + */ +#include <backport/magic.h> + +#undef hlist_entry_safe +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +#define hlist_for_each_entry4(tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});\ + pos = pos->next) + +#define hlist_for_each_entry_safe5(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});\ + pos = n) + +#define hlist_for_each_entry3(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); \ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +#define hlist_for_each_entry_safe4(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member); \ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + +#undef hlist_for_each_entry +#define hlist_for_each_entry(...) \ + macro_dispatcher(hlist_for_each_entry, __VA_ARGS__)(__VA_ARGS__) +#undef hlist_for_each_entry_safe +#define hlist_for_each_entry_safe(...) \ + macro_dispatcher(hlist_for_each_entry_safe, __VA_ARGS__)(__VA_ARGS__) + +#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 */ + +#ifndef list_next_entry +/** + * list_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_struct within the struct. + */ +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) +#endif /* list_next_entry */ + +#ifndef list_last_entry +/** + * 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) +#endif + +#endif /* __BACKPORT_LIST_H */ |