From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6Ky0-0007mN-Em for qemu-devel@nongnu.org; Sun, 13 Jul 2014 10:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X6Kxs-0001Vy-3h for qemu-devel@nongnu.org; Sun, 13 Jul 2014 10:41:28 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:37053) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6Kxr-0001Tl-AK for qemu-devel@nongnu.org; Sun, 13 Jul 2014 10:41:20 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Jul 2014 00:41:14 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 6FF032CE8040 for ; Mon, 14 Jul 2014 00:41:12 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s6DEOQGc31785148 for ; Mon, 14 Jul 2014 00:24:28 +1000 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s6DEfARL021808 for ; Mon, 14 Jul 2014 00:41:10 +1000 From: Alexey Kardashevskiy Date: Mon, 14 Jul 2014 00:41:08 +1000 Message-Id: <1405262468-8391-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH] qom: Make object_child_foreach safe for objects removal List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Paolo Bonzini , Alexander Graf , =?UTF-8?q?Andreas=20F=C3=A4rber?= Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible. This makes object_child_foreach() use QTAILQ_FOREACH_SAFE(). Signed-off-by: Alexey Kardashevskiy --- The problem I am trying to solve is: there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one. I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child() is static and we probably do not want to make it public. --- qom/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index 0e8267b..4a814dc 100644 --- a/qom/object.c +++ b/qom/object.c @@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque), int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque), void *opaque) { - ObjectProperty *prop; + ObjectProperty *prop, *next; int ret = 0; - QTAILQ_FOREACH(prop, &obj->properties, node) { + QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) { if (object_property_is_child(prop)) { ret = fn(prop->opaque, opaque); if (ret != 0) { -- 2.0.0