summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2011-11-11 22:51:13 -0800
committerGeoff Levand <geoff@infradead.org>2011-11-11 22:51:13 -0800
commitf5e1863e0e0a4fae56192cd588deb687edbfcda4 (patch)
tree583990575814180e7260aecf5e2bd3255331045f
parent62cf2ababe1046b88bf225db3d2ec7187c634812 (diff)
downloadpetitboot-f5e1863e0e0a4fae56192cd588deb687edbfcda4.zip
petitboot-f5e1863e0e0a4fae56192cd588deb687edbfcda4.tar.gz
Return NULL for head list_entry
Signed-off-by: Geoff Levand <geoff@infradead.org>
-rw-r--r--lib/list/list.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/list/list.h b/lib/list/list.h
index dfe4813..d93f8a8 100644
--- a/lib/list/list.h
+++ b/lib/list/list.h
@@ -22,17 +22,19 @@ struct list {
#define list_for_each(_list, _pos) \
for (_pos = (_list)->head.next; _pos != ((_list)->head); _pos = _pos->next)
-#define list_entry(_ptr, _type, _member) \
- container_of(_ptr, _type, _member)
+#define list_entry(_ptr, _type, _member, _list) \
+ (&container_of(_ptr, _type, _member)->_member == &((_list)->head) \
+ ? NULL \
+ : container_of(_ptr, _type, _member))
#define list_for_each_entry(_list, _pos, _member) \
- for (_pos = list_entry((_list)->head.next, typeof(*_pos), _member); \
- &_pos->_member != &(_list)->head; \
- _pos = list_entry(_pos->_member.next, typeof(*_pos), _member))
+ for (_pos = list_entry((_list)->head.next, typeof(*_pos), _member, _list); \
+ _pos; \
+ _pos = list_entry(_pos->_member.next, typeof(*_pos), _member, _list))
#define list_for_each_entry_continue(_list, _pos, _member) \
- for (; &_pos->_member != &(_list)->head; \
- _pos = list_entry(_pos->_member.next, typeof(*_pos), _member))
+ for (; _pos; \
+ _pos = list_entry(_pos->_member.next, typeof(*_pos), _member, _list))
#define STATIC_LIST(_list) static struct list _list = { \
.head = { \
OpenPOWER on IntegriCloud