From patchwork Fri Jan 25 11:46:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 215647 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 BABD92C0091 for ; Fri, 25 Jan 2013 23:31:16 +1100 (EST) Received: from localhost ([::1]:35205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyiR8-0004FU-Ro for incoming@patchwork.ozlabs.org; Fri, 25 Jan 2013 07:31:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyiQv-000474-UO for qemu-devel@nongnu.org; Fri, 25 Jan 2013 07:31:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyiQp-0006h6-6e for qemu-devel@nongnu.org; Fri, 25 Jan 2013 07:31:01 -0500 Received: from mail-qe0-f45.google.com ([209.85.128.45]:53392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tyhkd-0005BF-1W for qemu-devel@nongnu.org; Fri, 25 Jan 2013 06:47:19 -0500 Received: by mail-qe0-f45.google.com with SMTP id b4so66414qen.32 for ; Fri, 25 Jan 2013 03:47:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=pJgj/As6+9yGechi6/M9GSs7GRb8k9nXF2BHOFLtj/8=; b=LaG9hqARMDYxyY5j5n9VbpYTu7L9Ou1WNP6mRTcDAal9b3OSPum8geO6/BBoMyjQUg QN7Tb0dB0vsOF307Ub7qaXtzh/9tfVi5TtvUVlpBG3wKiThtxoFw9joX0XInQPYZKQEj 98JSAs0KOqd6Datw4xihEbyFAdzjEYSqYmxwKQ0vGy2IeI/xS9z7KWrprB3Jkt5qzEZU uwZIh/+EQ9sGi/inBkO62Cpc8FgOX+61do8/xIMoW/VxNgwjyto7b5nqfHWvdCoBOsRc AYefadBQoX27nVWuDH5E45x9RTff6siqkUwxNmjYaL21WbeO1KIJmhsZPcEeHsExQCow TVTA== X-Received: by 10.224.179.75 with SMTP id bp11mr5567669qab.22.1359114438564; Fri, 25 Jan 2013 03:47:18 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id eg9sm419389qab.7.2013.01.25.03.47.16 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 25 Jan 2013 03:47:17 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 25 Jan 2013 12:46:53 +0100 Message-Id: <1359114420-16149-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1359114420-16149-1-git-send-email-pbonzini@redhat.com> References: <1359114420-16149-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.45 Cc: afaerber@suse.de Subject: [Qemu-devel] [PATCH v3 05/12] 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 59dce62..78eedf0 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -64,7 +64,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; } @@ -82,9 +85,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)),