[PATCH 10/20] libvirt-nodedev.c: remove return value from virNodeDeviceFree()

Daniel Henrique Barboza danielhb413 at gmail.com
Mon Jan 4 12:54:34 UTC 2021


The function returns -1 on error, but no caller is actually checking
the return value. Making it 'void' makes more sense with its
current use.

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 include/libvirt/libvirt-nodedev.h |  2 +-
 src/libvirt-nodedev.c             | 15 +++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index eab8abf6ab..5634980a75 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -114,7 +114,7 @@ char *                  virNodeDeviceGetXMLDesc (virNodeDevicePtr dev,
                                                  unsigned int flags);
 
 int                     virNodeDeviceRef        (virNodeDevicePtr dev);
-int                     virNodeDeviceFree       (virNodeDevicePtr dev);
+void                    virNodeDeviceFree       (virNodeDevicePtr dev);
 
 int                     virNodeDeviceDettach    (virNodeDevicePtr dev);
 int                     virNodeDeviceDetachFlags(virNodeDevicePtr dev,
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
index eb8c735a8c..fcca40f47b 100644
--- a/src/libvirt-nodedev.c
+++ b/src/libvirt-nodedev.c
@@ -445,19 +445,26 @@ virNodeDeviceListCaps(virNodeDevicePtr dev,
  * Drops a reference to the node device, freeing it if
  * this was the last reference.
  *
- * Returns the 0 for success, -1 for error.
+ * Throws a VIR_ERR_INVALID_NODE_DEVICE error if @dev is
+ * not a valid node device. Does nothing if @dev is
+ * NULL.
  */
-int
+void
 virNodeDeviceFree(virNodeDevicePtr dev)
 {
+    if (!dev)
+        return;
+
     VIR_DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
 
     virResetLastError();
 
-    virCheckNodeDeviceReturn(dev, -1);
+    virCheckNodeDeviceGoto(dev, invalid_device);
 
     virObjectUnref(dev);
-    return 0;
+
+ invalid_device:
+    return;
 }
 
 
-- 
2.26.2




More information about the libvir-list mailing list