util: refactor mdev_types methods return code usage

Remove mix of array length and error code in the return code.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Boris Fiuczynski 2020-10-23 19:31:45 +02:00 committed by Ján Tomko
parent 65c1f47760
commit da5cf518ad
3 changed files with 16 additions and 14 deletions

View File

@ -2588,7 +2588,7 @@ virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath,
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 */
@ -2598,13 +2598,11 @@ virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath,
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;

View File

@ -528,7 +528,8 @@ void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr)
ssize_t
virMediatedDeviceGetMdevTypes(const char *sysfspath,
virMediatedDeviceTypePtr **types)
virMediatedDeviceTypePtr **types,
size_t *ntypes)
{
ssize_t ret = -1;
int dirret = -1;
@ -537,7 +538,7 @@ virMediatedDeviceGetMdevTypes(const char *sysfspath,
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);
@ -558,7 +559,7 @@ virMediatedDeviceGetMdevTypes(const char *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;
}
@ -566,10 +567,11 @@ virMediatedDeviceGetMdevTypes(const char *sysfspath,
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;
@ -580,7 +582,8 @@ static const char *unsupported = N_("not supported on non-linux platforms");
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;

View File

@ -151,7 +151,8 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath,
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);