]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_conf: Make virCPUDefFilterFeatures return void
authorJiri Denemark <jdenemar@redhat.com>
Fri, 24 Oct 2025 13:07:45 +0000 (15:07 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 3 Nov 2025 11:33:26 +0000 (12:33 +0100)
The only thing that can fail inside virCPUDefFilterFeatures is
VIR_DELETE_ELEMENT_INPLACE macro. The macro just calls
virDeleteElementsN, which reports a warning when all elements to be
removed are not within the array bounds and returns -1. The function
succeeds otherwise. But since VIR_DELETE_ELEMENT_INPLACE sets the number
of elements to be removed to 1 and we call it with i < cpu->nfeatures,
the safety check in virDeleteElementsN will never fail. And even if we
theoretically called it with wrong arguments, it just wouldn't do
anything.

Thus we can safely assume VIR_DELETE_ELEMENT_INPLACE always succeeds in
virCPUDefFilterFeatures and avoid reporting any errors to simplify
callers.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/qemu/qemu_capabilities.c
src/qemu/qemu_domain.c
src/qemu/qemu_process.c

index 31425783baaff167f57f4366569d8cb7c65b3b0c..7aeedf64f5f109c10a1ae58a01398cf109768ec5 100644 (file)
@@ -1017,7 +1017,7 @@ virCPUDefListExplicitFeatures(const virCPUDef *def)
 }
 
 
-int
+void
 virCPUDefFilterFeatures(virCPUDef *cpu,
                         virCPUDefFeatureFilter filter,
                         void *opaque)
@@ -1031,11 +1031,10 @@ virCPUDefFilterFeatures(virCPUDef *cpu,
         }
 
         VIR_FREE(cpu->features[i].name);
-        if (VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures) < 0)
-            return -1;
-    }
 
-    return 0;
+        /* Safe to ignore as an error is returned only for invalid arguments */
+        ignore_value(VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures));
+    }
 }
 
 
index 28e26303ef046ba823ed7c74f3c2aa1adcc072fe..cfb8f1a46193e99a2e9e789d1229363fcf9ad2f3 100644 (file)
@@ -260,7 +260,7 @@ virCPUFeatureDef *
 virCPUDefFindFeature(const virCPUDef *def,
                      const char *name);
 
-int
+void
 virCPUDefFilterFeatures(virCPUDef *cpu,
                         virCPUDefFeatureFilter filter,
                         void *opaque);
index 83946123be67919b227a891eb2f5e5a1ff1d1695..2c966e7ef03b234c385fea0d5b41fe3d4e6be5ee 100644 (file)
@@ -4023,17 +4023,14 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps,
 
     if (ARCH_IS_X86(qemuCaps->arch) &&
         !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_UNAVAILABLE_FEATURES)) {
-        if (cpu &&
-            virCPUDefFilterFeatures(cpu, virCPUx86FeatureFilterDropMSR, NULL) < 0)
-            goto error;
+        if (cpu)
+            virCPUDefFilterFeatures(cpu, virCPUx86FeatureFilterDropMSR, NULL);
 
-        if (migCPU &&
-            virCPUDefFilterFeatures(migCPU, virCPUx86FeatureFilterDropMSR, NULL) < 0)
-            goto error;
+        if (migCPU)
+            virCPUDefFilterFeatures(migCPU, virCPUx86FeatureFilterDropMSR, NULL);
 
-        if (fullCPU &&
-            virCPUDefFilterFeatures(fullCPU, virCPUx86FeatureFilterDropMSR, NULL) < 0)
-            goto error;
+        if (fullCPU)
+            virCPUDefFilterFeatures(fullCPU, virCPUx86FeatureFilterDropMSR, NULL);
     }
 
     if (virQEMUCapsTypeIsAccelerated(type))
index 375e0e441a160663d663d58837b7b19cdc859ad8..227eee3646a41a2177174fa4e6a2f6361f7aaf28 100644 (file)
@@ -5319,8 +5319,7 @@ qemuDomainMakeCPUMigratable(virArch arch,
             g_auto(GStrv) keep = virCPUDefListExplicitFeatures(origCPU);
             data.keep = keep;
 
-            if (virCPUDefFilterFeatures(cpu, qemuDomainDropAddedCPUFeatures, &data) < 0)
-                return -1;
+            virCPUDefFilterFeatures(cpu, qemuDomainDropAddedCPUFeatures, &data);
         }
     }
 
index 9926998f8522bb9ce2853419d811fad8131f7d46..17eac5772bea07dc3e285ee19d932e897a9cb5bc 100644 (file)
@@ -6552,9 +6552,8 @@ qemuProcessUpdateGuestCPU(virDomainDef *def,
         def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
     }
 
-    if (virCPUDefFilterFeatures(def->cpu, virQEMUCapsCPUFilterFeatures,
-                                &def->os.arch) < 0)
-        return -1;
+    virCPUDefFilterFeatures(def->cpu, virQEMUCapsCPUFilterFeatures,
+                            &def->os.arch);
 
     if (def->cpu->deprecated_feats) {
         virCPUFeaturePolicy policy = VIR_CPU_FEATURE_REQUIRE;