From 71db0de897afe747d396134334e87a806be0beff Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Wed, 2 Oct 2013 07:00:15 +0200
Subject: [PATCH 3/8] Another fix for hlist_for_each_entry_safe.
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1380697219-1860-4-git-send-email-kraxel@redhat.com>
Patchwork-id: 54627
O-Subject: [RHEL-7 seabios PATCH 3/7] Another fix for hlist_for_each_entry_safe.
Bugzilla: 947051
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Bandan Das <bsd@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
From: Kevin O'Connor <kevin@koconnor.net>
Although the previous patch does fix hlist_for_each_entry_safe for the
common case, it doesn't work correctly when deleting the current
node. To fix this, introduce two macros - hlist_for_each_entry_safe
for iterating through a list that can be modified, and
hlist_for_each_entry_pprev for those users that only need access to
the "pprev" pointer.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
(cherry picked from commit 030a58a05e595694dccfa958563103d2f0644231)
[ rhel-6: pick list.h changes only ]
Conflicts:
src/boot.c
src/pciinit.c
src/pmm.c
---
src/list.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
src/list.h | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/src/list.h b/src/list.h
index 0f0909b..de656b9 100644
--- a/src/list.h
+++ b/src/list.h
@@ -66,7 +66,13 @@ hlist_add_after(struct hlist_node *n, struct hlist_node *prev)
; pos != container_of(NULL, typeof(*pos), member) \
; pos = container_of(pos->member.next, typeof(*pos), member))
-#define hlist_for_each_entry_safe(pos, pprev, head, member) \
+#define hlist_for_each_entry_safe(pos, n, head, member) \
+ for (pos = container_of((head)->first, typeof(*pos), member) \
+ ; pos != container_of(NULL, typeof(*pos), member) \
+ && ({ n = pos->member.next; 1; }) \
+ ; pos = container_of(n, typeof(*pos), member))
+
+#define hlist_for_each_entry_pprev(pos, pprev, head, member) \
for (pprev = &(head)->first \
; *pprev && ({ pos=container_of(*pprev, typeof(*pos), member); 1; }) \
; pprev = &(*pprev)->next)
--
1.7.1