From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdfOe-0000OQ-QM for qemu-devel@nongnu.org; Tue, 05 Nov 2013 07:06:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VdfOZ-0004xK-U8 for qemu-devel@nongnu.org; Tue, 05 Nov 2013 07:06:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdfOZ-0004x6-LZ for qemu-devel@nongnu.org; Tue, 05 Nov 2013 07:06:07 -0500 Message-ID: <5278DF2D.2080206@redhat.com> Date: Tue, 05 Nov 2013 05:06:05 -0700 From: Eric Blake MIME-Version: 1.0 References: <1383141276-19230-1-git-send-email-stefanha@redhat.com> <1383141276-19230-8-git-send-email-stefanha@redhat.com> In-Reply-To: <1383141276-19230-8-git-send-email-stefanha@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="iKsnCX5RM1LHjFDUscKUIDngs1BBvThMk" Subject: Re: [Qemu-devel] [PATCH v3 7/7] qdev: drop misleading qdev_free() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Paolo Bonzini , Andreas Faerber , Markus Armbruster This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --iKsnCX5RM1LHjFDUscKUIDngs1BBvThMk Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 10/30/2013 07:54 AM, Stefan Hajnoczi wrote: > The qdev_free() function name is misleading since all the function does= > is unlink the device from its parent. The device is not necessarily > freed. Aha - you anticipated my comment on 2/7 :) >=20 > The device will be freed when its QObject refcount reaches zero. It is= > usual for the parent (bus) to hold the final reference but there are > cases where something else holds a reference so "free" is a misleading > name. >=20 > Call object_unparent(obj) directly instead of having a qdev wrapper > function. >=20 > Signed-off-by: Stefan Hajnoczi > --- > while ((kid =3D QTAILQ_FIRST(&bus->children)) !=3D NULL) { > DeviceState *dev =3D kid->child; > - qdev_free(dev); > + object_unparent(OBJECT(dev)); In most cases, you are just expanding the old call inline... > } > if (bus->parent) { > QLIST_REMOVE(bus, sibling); > diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c > index 619fe47..8dbc3c1 100644 > --- a/hw/pci/pci-hotplug-old.c > +++ b/hw/pci/pci-hotplug-old.c > @@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor = *mon, > } > dev =3D pci_create(bus, devfn, "virtio-blk-pci"); > if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0)= { > - qdev_free(&dev->qdev); > + object_unparent(OBJECT(dev)); =2E..but in this case, you are unparenting OBJECT(dev) in the new code while the old code unparented OBJECT(&dev->qdev). Ah, I see - qdev is the first member of dev, so it is the same pointer address. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --iKsnCX5RM1LHjFDUscKUIDngs1BBvThMk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSeN8tAAoJEKeha0olJ0NqaMcIAIpShdCUpngafl8wKY4mT+hF /KydgGPxoevpGj5Xl1ypTcHbetA1LtLksAKuca1xnlL6lpEu1wQEk3g6VoRIhHgY NY9uEsQpRsJDf7bq36N7mXSaA47Co1PwOnL3PHlaCeUoXO8YoeHn7RO4ddgODaLl ExAEpgzt9mqgyk6qVEV3VoY+NEf7FkbIXoXfrqNBTB/E+33ly8NNu57nTcj70/PL G9lUKmrMylzkuTWsbReu3IML2EgSTrHB2+PJUD+5PhI5u5tVDYNEVi3uz1S4+Mf2 2Nu7AEa5SbwDxA1BnFGZemuWvETfSG9PhjxQOnov0h7CqgB/QinrJNxXSQQOk08= =RjF7 -----END PGP SIGNATURE----- --iKsnCX5RM1LHjFDUscKUIDngs1BBvThMk--