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?
pgpUVc3cYWFXa.pgp
Description: PGP signature
