virNodeDevCapPCIDevPtr pci_dev)
{
virMediatedDeviceTypePtr *types = NULL;
- int rc = 0;
+ size_t ntypes = 0;
size_t i;
/* this could be a refresh, so clear out the old data */
pci_dev->nmdev_types = 0;
pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
- rc = virMediatedDeviceGetMdevTypes(sysfspath, &types);
-
- if (rc <= 0)
- return rc;
+ if (virMediatedDeviceGetMdevTypes(sysfspath, &types, &ntypes) < 0)
+ return -1;
pci_dev->mdev_types = g_steal_pointer(&types);
- pci_dev->nmdev_types = rc;
+ pci_dev->nmdev_types = ntypes;
pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
return 0;
ssize_t
virMediatedDeviceGetMdevTypes(const char *sysfspath,
- virMediatedDeviceTypePtr **types)
+ virMediatedDeviceTypePtr **types,
+ size_t *ntypes)
{
ssize_t ret = -1;
int dirret = -1;
g_autofree char *types_path = NULL;
g_autoptr(virMediatedDeviceType) mdev_type = NULL;
virMediatedDeviceTypePtr *mdev_types = NULL;
- size_t ntypes = 0;
+ size_t nmdev_types = 0;
size_t i;
types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath);
if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
goto cleanup;
- if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0)
+ if (VIR_APPEND_ELEMENT(mdev_types, nmdev_types, mdev_type) < 0)
goto cleanup;
}
goto cleanup;
*types = g_steal_pointer(&mdev_types);
- ret = ntypes;
- ntypes = 0;
+ *ntypes = nmdev_types;
+ nmdev_types = 0;
+ ret = 0;
cleanup:
- for (i = 0; i < ntypes; i++)
+ for (i = 0; i < nmdev_types; i++)
virMediatedDeviceTypeFree(mdev_types[i]);
VIR_FREE(mdev_types);
return ret;
ssize_t
virMediatedDeviceGetMdevTypes(const char *sysfspath G_GNUC_UNUSED,
- virMediatedDeviceTypePtr **types G_GNUC_UNUSED)
+ virMediatedDeviceTypePtr **types G_GNUC_UNUSED,
+ size_t *ntypes G_GNUC_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
ssize_t
virMediatedDeviceGetMdevTypes(const char *sysfspath,
- virMediatedDeviceTypePtr **types);
+ virMediatedDeviceTypePtr **types,
+ size_t *ntypes);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDevice, virMediatedDeviceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceType, virMediatedDeviceTypeFree);