Remove mix of array length and error code in the return code.
Signed-off-by: Boris Fiuczynski <fiuczy(a)linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk(a)linux.ibm.com>
---
src/conf/node_device_conf.c | 10 ++++------
src/util/virmdev.c | 14 ++++++++------
src/util/virmdev.h | 3 ++-
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index db1258436a..af8edded3c 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2574,7 +2574,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 */
@@ -2584,13 +2584,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 80f5f2a767..b02005bd1a 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);
VIR_DIR_CLOSE(dir);
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);
--
2.25.1