]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: refactor mdev_types methods return code usage
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 23 Oct 2020 17:31:45 +0000 (19:31 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 4 Nov 2020 18:14:07 +0000 (19:14 +0100)
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>
src/conf/node_device_conf.c
src/util/virmdev.c
src/util/virmdev.h

index dbb87737bb85c229e6c0a4117e8459313fdecfaf..5466f8d94ddc87a1c35fe8893fb2f2d8713e75c4 100644 (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;
index 3ed65f2abf2cd28e181ee467958ec1479286a971..b6df353d56137071dc4e0c0bb7bfd23b231d9cac 100644 (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;
index 846e1662e75d90b0914344c918237fceaee05508..b6563a94fc67e68626655e809a2d39e7a3ba97df 100644 (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);