list: Fix seg fault with list_for_each_entry_safe
authorGeoff Levand <geoff@infradead.org>
Wed, 24 Apr 2013 03:41:07 +0000 (20:41 -0700)
committerGeoff Levand <geoff@infradead.org>
Wed, 24 Apr 2013 03:41:07 +0000 (20:41 -0700)
Signed-off-by: Geoff Levand <geoff@infradead.org>
lib/list/list.h

index 97fb615cdb9fd1bc8361c876c2e063fb11a41b32..6000320da3e38ee1e05f4b7e7298d91599481d97 100644 (file)
@@ -41,13 +41,11 @@ struct list {
        for (; _pos; _pos = list_next_entry(_list, _pos, _member))
 
 #define list_for_each_entry_safe(_list, _pos, _tmp, _member) \
        for (; _pos; _pos = list_next_entry(_list, _pos, _member))
 
 #define list_for_each_entry_safe(_list, _pos, _tmp, _member) \
-       for (_pos = container_of((_list)->head.next, typeof(*_pos), _member), \
-               _tmp = container_of(_pos->_member.next, typeof(*_pos), \
-                               _member); \
-            &_pos->_member != &(_list)->head; \
-            _pos = _tmp, \
-               _tmp = list_entry(_tmp->_member.next, typeof(*_pos), \
-                               _member, _list))
+       for (_pos = list_entry((_list)->head.next, typeof(*_pos), _member, _list), \
+               _tmp = list_entry(_pos->_member.next, typeof(*_pos), _member, _list); \
+       _pos; \
+       _pos = _tmp, \
+       _tmp = _tmp ? list_entry(_tmp->_member.next, typeof(*_pos), _member, _list) : NULL)
 
 #define DEFINE_LIST(_list) struct list _list = { \
        .head = { \
 
 #define DEFINE_LIST(_list) struct list _list = { \
        .head = { \