]> xenbits.xensource.com Git - libvirt.git/commitdiff
ppc64Compute: Avoid possible NULL dereference
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Jun 2016 09:47:11 +0000 (11:47 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Jun 2016 09:56:50 +0000 (11:56 +0200)
cpu/cpu_ppc64.c: In function 'ppc64Compute':
cpu/cpu_ppc64.c:620:27: error: potential null pointer dereference [-Werror=null-dereference]
     if (STRNEQ(guest_model->name, host_model->name)) {
                ~~~~~~~~~~~^~~
cpu/cpu_ppc64.c:620:9: note: in expansion of macro 'STRNEQ'
     if (STRNEQ(guest_model->name, host_model->name)) {
         ^~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/cpu/cpu_ppc64.c

index 799fb8e67c3cc03bcb550c54c0e62dc5b32f36e6..09f4596a13d41a45ca0e5f1cf5ba165fe877ff1f 100644 (file)
@@ -600,23 +600,23 @@ ppc64Compute(virCPUDefPtr host,
         case VIR_CPU_MODE_HOST_PASSTHROUGH:
             /* host-model and host-passthrough:
              * the guest CPU is the same as the host */
-            if (!(guest_model = ppc64ModelCopy(host_model)))
-                goto cleanup;
+            guest_model = ppc64ModelCopy(host_model);
             break;
 
         case VIR_CPU_MODE_CUSTOM:
             /* custom:
              * look up guest CPU information */
-            if (!(guest_model = ppc64ModelFromCPU(cpu, map)))
-                goto cleanup;
+            guest_model = ppc64ModelFromCPU(cpu, map);
             break;
         }
     } else {
         /* Other host CPU information */
-        if (!(guest_model = ppc64ModelFromCPU(cpu, map)))
-            goto cleanup;
+        guest_model = ppc64ModelFromCPU(cpu, map);
     }
 
+    if (!guest_model)
+        goto cleanup;
+
     if (STRNEQ(guest_model->name, host_model->name)) {
         VIR_DEBUG("host CPU model does not match required CPU model %s",
                   guest_model->name);