From patchwork Wed Dec 5 20:44:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 203940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 43BBA2C0106 for ; Thu, 6 Dec 2012 07:45:22 +1100 (EST) Received: from localhost ([::1]:47349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgLqK-0000BE-CD for incoming@patchwork.ozlabs.org; Wed, 05 Dec 2012 15:45:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgLpy-0008P9-9c for qemu-devel@nongnu.org; Wed, 05 Dec 2012 15:44:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgLpw-0001C7-Qs for qemu-devel@nongnu.org; Wed, 05 Dec 2012 15:44:58 -0500 Received: from mail-ee0-f45.google.com ([74.125.83.45]:34805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgLpw-0001A6-LA for qemu-devel@nongnu.org; Wed, 05 Dec 2012 15:44:56 -0500 Received: by mail-ee0-f45.google.com with SMTP id d49so3380479eek.4 for ; Wed, 05 Dec 2012 12:44:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=6EOTLI2H8MyceZYgYMwG4N0DpCArS5HStKSm7uwQyRI=; b=uSUdukJtfX75xBMJP+pv0LxwVtulOfG9ZCBd7Y2IuQl8DgI7TgK19ogJan9KUBxwkP 5kX5jizSYZe2L1QmPIi/AAtWuxjflgxe7vqWAP2z4pwrtI8w3p2YdgsD7DiBCTNX9/yb S6HBeYcIFm6vf9k02es7hojlecKp1eLfT+aj3rJJWx/AoZGc4XhOGwVZGlOHuoC7EXAV vvE+20jtVYEg+1RCOkcGgdDAoxiILQRJiWCdpx8zyG8f4DCK4cBgbcwy2EiyzzJKIMS7 PCoLVakJ1ELHmRCKZj5s7YgXZE3r754shqfoC7E35RzzVHNi+dh/gVNfi6+OEF1rthvX 86Yg== Received: by 10.14.3.195 with SMTP id 43mr64489737eeh.36.1354740296236; Wed, 05 Dec 2012 12:44:56 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-219-150.ip51.fastwebnet.it. [93.34.219.150]) by mx.google.com with ESMTPS id a44sm11396163eeo.7.2012.12.05.12.44.54 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Dec 2012 12:44:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 5 Dec 2012 21:44:35 +0100 Message-Id: <1354740282-20679-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1354740282-20679-1-git-send-email-pbonzini@redhat.com> References: <1354740282-20679-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.83.45 Cc: aliguori@us.ibm.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 04/11] qdev: add reference count to a device for the BusChild X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Each device has a reference through the BusChild. This reference was not accounted for, add it now. Signed-off-by: Paolo Bonzini --- hw/qdev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/qdev.c b/hw/qdev.c index e758131..87dfcb5 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -65,7 +65,10 @@ static void bus_remove_child(BusState *bus, DeviceState *child) snprintf(name, sizeof(name), "child[%d]", kid->index); QTAILQ_REMOVE(&bus->children, kid, sibling); + + /* This gives back ownership of kid->child back to us. */ object_property_del(OBJECT(bus), name, NULL); + object_unref(OBJECT(kid->child)); g_free(kid); return; } @@ -83,9 +86,11 @@ static void bus_add_child(BusState *bus, DeviceState *child) kid->index = bus->max_index++; kid->child = child; + object_ref(OBJECT(kid->child)); QTAILQ_INSERT_HEAD(&bus->children, kid, sibling); + /* This transfers ownership of kid->child to the property. */ snprintf(name, sizeof(name), "child[%d]", kid->index); object_property_add_link(OBJECT(bus), name, object_get_typename(OBJECT(child)),