7a3408
From 168e6ce50e183acb95a8ca49cee8114dd880f17a Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <168e6ce50e183acb95a8ca49cee8114dd880f17a@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Tue, 11 Aug 2015 17:15:54 +0200
7a3408
Subject: [PATCH] cpu: Simplify NULL handling in ppc64 driver
7a3408
7a3408
Use briefer checks, eg. (!model) instead of (model == NULL), and
7a3408
avoid initializing to NULL a pointer that would be assigned in
7a3408
the first line of the function anyway.
7a3408
7a3408
Also remove a pointless NULL assignment.
7a3408
7a3408
No functional changes.
7a3408
7a3408
(cherry picked from commit 4590f0678f7c74e988f53882e710a67a3b15fc68)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1250977
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/cpu/cpu_ppc64.c | 33 ++++++++++++++++-----------------
7a3408
 1 file changed, 16 insertions(+), 17 deletions(-)
7a3408
7a3408
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
7a3408
index 5140297..05ff8f2 100644
7a3408
--- a/src/cpu/cpu_ppc64.c
7a3408
+++ b/src/cpu/cpu_ppc64.c
7a3408
@@ -61,7 +61,7 @@ struct ppc64_map {
7a3408
 static void
7a3408
 ppc64ModelFree(struct ppc64_model *model)
7a3408
 {
7a3408
-    if (model == NULL)
7a3408
+    if (!model)
7a3408
         return;
7a3408
 
7a3408
     VIR_FREE(model->name);
7a3408
@@ -75,7 +75,7 @@ ppc64ModelFind(const struct ppc64_map *map,
7a3408
     struct ppc64_model *model;
7a3408
 
7a3408
     model = map->models;
7a3408
-    while (model != NULL) {
7a3408
+    while (model) {
7a3408
         if (STREQ(model->name, name))
7a3408
             return model;
7a3408
 
7a3408
@@ -92,7 +92,7 @@ ppc64ModelFindPVR(const struct ppc64_map *map,
7a3408
     struct ppc64_model *model;
7a3408
 
7a3408
     model = map->models;
7a3408
-    while (model != NULL) {
7a3408
+    while (model) {
7a3408
         if (model->data.pvr == pvr)
7a3408
             return model;
7a3408
 
7a3408
@@ -158,15 +158,15 @@ static struct ppc64_model *
7a3408
 ppc64ModelFromCPU(const virCPUDef *cpu,
7a3408
                   const struct ppc64_map *map)
7a3408
 {
7a3408
-    struct ppc64_model *model = NULL;
7a3408
+    struct ppc64_model *model;
7a3408
 
7a3408
-    if ((model = ppc64ModelFind(map, cpu->model)) == NULL) {
7a3408
+    if (!(model = ppc64ModelFind(map, cpu->model))) {
7a3408
         virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
                        _("Unknown CPU model %s"), cpu->model);
7a3408
         goto error;
7a3408
     }
7a3408
 
7a3408
-    if ((model = ppc64ModelCopy(model)) == NULL)
7a3408
+    if (!(model = ppc64ModelCopy(model)))
7a3408
         goto error;
7a3408
 
7a3408
     return model;
7a3408
@@ -181,7 +181,7 @@ static int
7a3408
 ppc64VendorLoad(xmlXPathContextPtr ctxt,
7a3408
                 struct ppc64_map *map)
7a3408
 {
7a3408
-    struct ppc64_vendor *vendor = NULL;
7a3408
+    struct ppc64_vendor *vendor;
7a3408
 
7a3408
     if (VIR_ALLOC(vendor) < 0)
7a3408
         return -1;
7a3408
@@ -264,7 +264,7 @@ ppc64ModelLoad(xmlXPathContextPtr ctxt,
7a3408
     }
7a3408
     model->data.pvr = pvr;
7a3408
 
7a3408
-    if (map->models == NULL) {
7a3408
+    if (!map->models) {
7a3408
         map->models = model;
7a3408
     } else {
7a3408
         model->next = map->models;
7a3408
@@ -303,16 +303,16 @@ ppc64MapLoadCallback(cpuMapElement element,
7a3408
 static void
7a3408
 ppc64MapFree(struct ppc64_map *map)
7a3408
 {
7a3408
-    if (map == NULL)
7a3408
+    if (!map)
7a3408
         return;
7a3408
 
7a3408
-    while (map->models != NULL) {
7a3408
+    while (map->models) {
7a3408
         struct ppc64_model *model = map->models;
7a3408
         map->models = model->next;
7a3408
         ppc64ModelFree(model);
7a3408
     }
7a3408
 
7a3408
-    while (map->vendors != NULL) {
7a3408
+    while (map->vendors) {
7a3408
         struct ppc64_vendor *vendor = map->vendors;
7a3408
         map->vendors = vendor->next;
7a3408
         ppc64VendorFree(vendor);
7a3408
@@ -350,7 +350,6 @@ ppc64MakeCPUData(virArch arch,
7a3408
 
7a3408
     cpuData->arch = arch;
7a3408
     cpuData->data.ppc64 = *data;
7a3408
-    data = NULL;
7a3408
 
7a3408
     return cpuData;
7a3408
 }
7a3408
@@ -417,7 +416,7 @@ ppc64Compute(virCPUDefPtr host,
7a3408
         !(guest_model = ppc64ModelFromCPU(cpu, map)))
7a3408
         goto cleanup;
7a3408
 
7a3408
-    if (guestData != NULL) {
7a3408
+    if (guestData) {
7a3408
         if (cpu->type == VIR_CPU_TYPE_GUEST &&
7a3408
             cpu->match == VIR_CPU_MATCH_STRICT &&
7a3408
             STRNEQ(guest_model->name, host_model->name)) {
7a3408
@@ -478,7 +477,7 @@ ppc64DriverDecode(virCPUDefPtr cpu,
7a3408
 
7a3408
     virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, -1);
7a3408
 
7a3408
-    if (data == NULL || (map = ppc64LoadMap()) == NULL)
7a3408
+    if (!data || !(map = ppc64LoadMap()))
7a3408
         return -1;
7a3408
 
7a3408
     if (!(model = ppc64ModelFindPVR(map, data->data.ppc64.pvr))) {
7a3408
@@ -512,7 +511,7 @@ ppc64DriverDecode(virCPUDefPtr cpu,
7a3408
 static void
7a3408
 ppc64DriverFree(virCPUDataPtr data)
7a3408
 {
7a3408
-    if (data == NULL)
7a3408
+    if (!data)
7a3408
         return;
7a3408
 
7a3408
     VIR_FREE(data);
7a3408
@@ -575,7 +574,7 @@ ppc64DriverBaseline(virCPUDefPtr *cpus,
7a3408
                     unsigned int nmodels ATTRIBUTE_UNUSED,
7a3408
                     unsigned int flags)
7a3408
 {
7a3408
-    struct ppc64_map *map = NULL;
7a3408
+    struct ppc64_map *map;
7a3408
     const struct ppc64_model *model;
7a3408
     const struct ppc64_vendor *vendor = NULL;
7a3408
     virCPUDefPtr cpu = NULL;
7a3408
@@ -667,7 +666,7 @@ ppc64DriverGetModels(char ***models)
7a3408
         goto error;
7a3408
 
7a3408
     model = map->models;
7a3408
-    while (model != NULL) {
7a3408
+    while (model) {
7a3408
         if (models) {
7a3408
             if (VIR_STRDUP(name, model->name) < 0)
7a3408
                 goto error;
7a3408
-- 
7a3408
2.5.0
7a3408