From 87d308708712ff6075c4dd54b0519b47fdad8816 Mon Sep 17 00:00:00 2001 From: Oleksandr Suvorov Date: Thu, 26 Mar 2020 12:44:27 +0200 Subject: Backports v5.4.27 Backports generated by toradex backports f6e8852f1ef28e6d3c9bae8400eb6a87a6b0c3e7 against mainline kernel tag v5.4.27 Signed-off-by: Oleksandr Suvorov --- backport-include/linux/list.h | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 backport-include/linux/list.h (limited to 'backport-include/linux/list.h') 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 +#include + +#if LINUX_VERSION_IS_LESS(3,9,0) +/** + * backport: + * + * commit 0bbacca7c3911451cea923b0ad6389d58e3d9ce9 + * Author: Sasha Levin + * Date: Thu Feb 7 12:32:18 2013 +1100 + * + * hlist: drop the node parameter from iterators + */ +#include + +#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 */ -- cgit v1.2.3