From: Eric Blake <eblake@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Andreas Faerber <afaerber@suse.de>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 7/7] qdev: drop misleading qdev_free() function
Date: Tue, 05 Nov 2013 05:06:05 -0700 [thread overview]
Message-ID: <5278DF2D.2080206@redhat.com> (raw)
In-Reply-To: <1383141276-19230-8-git-send-email-stefanha@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1811 bytes --]
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 :)
>
> 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.
>
> Call object_unparent(obj) directly instead of having a qdev wrapper
> function.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
> DeviceState *dev = 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 = 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));
...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 <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
next prev parent reply other threads:[~2013-11-05 12:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-30 13:54 [Qemu-devel] [PATCH v3 0/7] qdev and blockdev refcount leak fixes Stefan Hajnoczi
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 1/7] blockdev: fix drive_init() opts and bs_opts leaks Stefan Hajnoczi
2013-11-05 11:48 ` Eric Blake
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 2/7] qdev: unref qdev when device_add fails Stefan Hajnoczi
2013-11-05 11:50 ` Eric Blake
2013-11-05 15:28 ` Stefan Hajnoczi
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 3/7] libqtest: rename qmp() to qmp_discard_response() Stefan Hajnoczi
2013-11-05 11:52 ` Eric Blake
2013-11-06 15:24 ` Andreas Färber
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 4/7] libqtest: add qmp(fmt, ...) -> QDict* function Stefan Hajnoczi
2013-11-05 11:56 ` Eric Blake
2013-11-06 15:32 ` Andreas Färber
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 5/7] blockdev-test: add test case for drive_add duplicate IDs Stefan Hajnoczi
2013-11-05 11:57 ` Eric Blake
2013-11-06 15:36 ` Andreas Färber
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 6/7] qdev-monitor-test: add device_add leak test cases Stefan Hajnoczi
2013-11-05 11:58 ` Eric Blake
2013-11-06 15:38 ` Andreas Färber
2013-10-30 13:54 ` [Qemu-devel] [PATCH v3 7/7] qdev: drop misleading qdev_free() function Stefan Hajnoczi
2013-11-05 12:06 ` Eric Blake [this message]
2013-10-30 15:44 ` [Qemu-devel] [PATCH v3 0/7] qdev and blockdev refcount leak fixes Andreas Färber
2013-10-31 9:22 ` Stefan Hajnoczi
2013-11-06 10:30 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5278DF2D.2080206@redhat.com \
--to=eblake@redhat.com \
--cc=afaerber@suse.de \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.