From: Boris Fiuczynski Date: Fri, 23 Oct 2020 17:31:45 +0000 (+0200) Subject: util: refactor mdev_types methods return code usage X-Git-Tag: v6.10.0-rc1~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da5cf518ad63af0f84ccbe3a874828bc0be75c07;p=thirdparty%2Flibvirt.git 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 Reviewed-by: Bjoern Walk Signed-off-by: Ján Tomko Reviewed-by: Ján Tomko --- diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index dbb87737bb..5466f8d94d 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -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; diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 3ed65f2abf..b6df353d56 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -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; diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 846e1662e7..b6563a94fc 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -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);