From patchwork Mon Jan 21 12:30:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 214151 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 14F952C007C for ; Tue, 22 Jan 2013 00:33:46 +1100 (EST) Received: from localhost ([::1]:41204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxGWq-0005eq-HJ for incoming@patchwork.ozlabs.org; Mon, 21 Jan 2013 07:31:08 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxGWQ-00053a-Dl for qemu-devel@nongnu.org; Mon, 21 Jan 2013 07:30:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxGWO-0006du-QY for qemu-devel@nongnu.org; Mon, 21 Jan 2013 07:30:42 -0500 Received: from mail-ee0-f48.google.com ([74.125.83.48]:65098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxGWO-0006dm-KM for qemu-devel@nongnu.org; Mon, 21 Jan 2013 07:30:40 -0500 Received: by mail-ee0-f48.google.com with SMTP id t10so2902846eei.21 for ; Mon, 21 Jan 2013 04:30:40 -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=820+UMDrZ0bxQ6j4UnHJePzRQ/UtviMM6pLCL+f+/5I=; b=wpW2PHJfaSK5LwDhsdPvEWI6GMK02+WeMEdUBkqbNZVjxEcTZQ/ZSGlWT4FkS79ZGm MAfV/UAne6RDH91WGAnaRmy2WNE3458KRhyVN0m/YE0JVRphUQBJfyFTx6Rrv6M/2osZ wtQPmtHOfNILKwkKJiN0UFwBVMc9dUiRN9i3la7BJp1druleyvikqRGpXn5IQ9aj02gZ +jQdJVZvjHp+x74xGjrU+hiYT1ipkJtOOpgCZ8GemtZEUw4BkC5q2CM3pyinPVi7sat8 ML5KsSnJkKERwN+rOpkv/FxhkJAiRhxH3k/usJglAUf67q20q1/m8qwWnAokSs5TerqJ ibwg== X-Received: by 10.14.219.3 with SMTP id l3mr59858064eep.5.1358771439931; Mon, 21 Jan 2013 04:30:39 -0800 (PST) Received: from yakj.lan (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id 46sm22102581eeg.4.2013.01.21.04.30.37 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 21 Jan 2013 04:30:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2013 13:30:15 +0100 Message-Id: <1358771422-14282-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1358771422-14282-1-git-send-email-pbonzini@redhat.com> References: <1358771422-14282-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.48 Cc: aliguori@us.ibm.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 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 b473bd7..f88a8a4 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)),