]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: Fix retval of some functions declared to return an int
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 14 May 2025 14:14:39 +0000 (16:14 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 15 May 2025 08:49:41 +0000 (10:49 +0200)
There are couple of functions (virCHDomainPrepareHostdevPCI(),
qemuDomainPrepareHostdevPCI(),
virStorageBackendRBDSetAllocation(), virCommandHandshakeChild())
that are declared to return an integer, but in fact return a
boolean. This may lead to incorrect behaviour. Fix their retvals.

This diff was generated using the following semantic patch:

  @@
  identifier foo;
  @@

  int foo(...) {
      <+...
  (
  -   return true;
  +   return 0;
  |
  -   return false;
  +   return -1;
  )
      ...+>
  }

Each function and its callers were then inspected to see what
retvals are expected.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/ch/ch_hostdev.c
src/storage/storage_backend_rbd.c
src/util/vircommand.c

index 641032de30c208d86249be7549276ce8dbb381dc..34eb025c97137f93592a33691efacb9f662eb4ca 100644 (file)
@@ -69,20 +69,20 @@ virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev)
         if (!supportsPassthroughVFIO) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("host doesn't support VFIO PCI passthrough"));
-            return false;
+            return -1;
         }
         break;
 
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("host doesn't support legacy PCI passthrough"));
-        return false;
+        return -1;
 
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("CH does not support device assignment mode '%1$s'"),
                        virDeviceHostdevPCIDriverNameTypeToString(*driverName));
-        return false;
+        return -1;
 
     default:
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
@@ -90,7 +90,7 @@ virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev)
         break;
     }
 
-    return true;
+    return 0;
 }
 
 int
index fd46c8be552a2b25a7a7c4ae9b8a01bbc24bba83..038a1a9e34bf8c3aa44aa182d655435991c925a8 100644 (file)
@@ -516,7 +516,7 @@ virStorageBackendRBDSetAllocation(virStorageVolDef *vol G_GNUC_UNUSED,
                                   rbd_image_info_t *info G_GNUC_UNUSED)
 {
     virReportUnsupportedError();
-    return false;
+    return -1;
 }
 #endif
 
index ea52acfbb8876ef51f5eea6207f282493e37b1c8..d9e4c0181fc96abc5f26ca1f1f8d04da0e03de99 100644 (file)
@@ -397,7 +397,7 @@ virCommandHandshakeChild(virCommand *cmd)
     int rv;
 
     if (!cmd->handshake)
-       return true;
+       return 0;
 
     VIR_DEBUG("Notifying parent for handshake start on %d",
               cmd->handshakeWait[1]);