[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4] tests: Functions bus_foreach and device_find
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v4] tests: Functions bus_foreach and device_find from libqos virtio API |
Date: |
Wed, 9 Jul 2014 10:57:00 +0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Fri, Jul 04, 2014 at 12:36:49AM +0200, Marc MarĂ wrote:
> +static void qvirtio_pci_foreach_callback(
> + QPCIDevice *dev, int devfn, void *data)
> +{
> + QVirtioPCIForeachData *d = data;
> + QVirtioPCIDevice *vpcidev = qpcidevice_to_qvirtiodevice(dev);
> +
> + if (vpcidev->vdev.device_type == d->device_type) {
> + d->func(&vpcidev->vdev, d->user_data);
> + }
> +
> + g_free(vpcidev);
Fine for now but eventually I think we need to pass ownership of vpcidev
to ->func() and only free vpcidev if the device type didn't match.
> +QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
> +{
> + QVirtioPCIDevice *dev;
> +
> + dev = g_malloc0(sizeof(*dev));
> + qvirtio_pci_foreach(bus, device_type, qvirtio_pci_assign_device, dev);
> +
> + return dev;
> +}
What if the device is not found, should we return NULL?
pgpI7bTzGNL7o.pgp
Description: PGP signature