]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
tools/libxc: Drop other examples of the 'goto x; } else if' antipattern
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 18 Dec 2019 22:08:02 +0000 (22:08 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 20 Dec 2019 16:08:00 +0000 (16:08 +0000)
None of these are buggy, but the resulting code is more robust.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xc_dom_core.c
tools/libxc/xc_misc.c
tools/libxc/xc_resource.c
tools/libxc/xc_sr_common.c
tools/libxc/xc_sr_restore.c
tools/libxc/xc_sr_restore_x86_hvm.c
tools/libxc/xc_sr_restore_x86_pv.c

index 9bd04cb2d554a5f3075b410514524152be4e18ca..73fe09fe1864df1735970142f285301b84bc4d7a 100644 (file)
@@ -225,7 +225,8 @@ void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
                      "tried to map file which is too large");
         goto err;
     }
-    else if ( !*size )
+
+    if ( !*size )
     {
         xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "'%s': zero length file", filename);
index 0b21a6aca4c35ed1c1cc84231dd6a59835ae0c5d..093fa4408199de0fc17b0588af497d0467771e6e 100644 (file)
@@ -872,7 +872,8 @@ int xc_livepatch_list(xc_interface *xch, const unsigned int max,
             xc_hypercall_bounce_post(xch, metadata_len);
             continue;
         }
-        else if ( rc < 0 ) /* For all other errors we bail out. */
+
+        if ( rc < 0 ) /* For all other errors we bail out. */
             break;
 
         if ( !version )
index 3abadbdcfce2d38a20127abea89e3b2157a82db9..3394cc1833055e285ceb0e9e3390bc397c334e08 100644 (file)
@@ -133,10 +133,11 @@ int xc_resource_op(xc_interface *xch, uint32_t nr_ops, xc_resource_op_t *ops)
 {
     if ( nr_ops == 1 )
         return xc_resource_op_one(xch, ops);
-    else if ( nr_ops > 1 )
+
+    if ( nr_ops > 1 )
         return xc_resource_op_multi(xch, nr_ops, ops);
-    else
-        return -1;
+
+    return -1;
 }
 
 /*
index 79b9c3e94062ff9a03fc5ed5e71eafb10e5bfbe5..6b887b30534ad965ea6b6d451ad8f978aadcb5ec 100644 (file)
@@ -102,7 +102,8 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
         PERROR("Failed to read Record Header from stream");
         return -1;
     }
-    else if ( rhdr.length > REC_LENGTH_MAX )
+
+    if ( rhdr.length > REC_LENGTH_MAX )
     {
         ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
               rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
index 1ac404b97b0184fe348e159e166d2f1b5263cd9c..98038096c7d11f2f79c8c17930319a02364464c1 100644 (file)
@@ -28,18 +28,21 @@ static int read_headers(struct xc_sr_context *ctx)
         ERROR("Invalid marker: Got 0x%016"PRIx64, ihdr.marker);
         return -1;
     }
-    else if ( ihdr.id != IHDR_ID )
+
+    if ( ihdr.id != IHDR_ID )
     {
         ERROR("Invalid ID: Expected 0x%08x, Got 0x%08x", IHDR_ID, ihdr.id);
         return -1;
     }
-    else if ( ihdr.version != IHDR_VERSION )
+
+    if ( ihdr.version != IHDR_VERSION )
     {
         ERROR("Invalid Version: Expected %d, Got %d",
               IHDR_VERSION, ihdr.version);
         return -1;
     }
-    else if ( ihdr.options & IHDR_OPT_BIG_ENDIAN )
+
+    if ( ihdr.options & IHDR_OPT_BIG_ENDIAN )
     {
         ERROR("Unable to handle big endian streams");
         return -1;
@@ -345,12 +348,14 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
               rec->length, sizeof(*pages));
         goto err;
     }
-    else if ( pages->count < 1 )
+
+    if ( pages->count < 1 )
     {
         ERROR("Expected at least 1 pfn in PAGE_DATA record");
         goto err;
     }
-    else if ( rec->length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) )
+
+    if ( rec->length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) )
     {
         ERROR("PAGE_DATA record (length %u) too short to contain %u"
               " pfns worth of information", rec->length, pages->count);
@@ -383,7 +388,8 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
                   type, pfn, i);
             goto err;
         }
-        else if ( type < XEN_DOMCTL_PFINFO_BROKEN )
+
+        if ( type < XEN_DOMCTL_PFINFO_BROKEN )
             /* NOTAB and all L1 through L4 tables (including pinned) should
              * have a page worth of data in the record. */
             pages_of_data++;
index 4765a52f33774ed8102a8390686f17816256c57b..9763aaa8dcb2889f7d7ed74fb1a1f5614e51efad 100644 (file)
@@ -142,12 +142,14 @@ static int x86_hvm_setup(struct xc_sr_context *ctx)
               dhdr_type_to_str(ctx->restore.guest_type));
         return -1;
     }
-    else if ( ctx->restore.guest_page_size != PAGE_SIZE )
+
+    if ( ctx->restore.guest_page_size != PAGE_SIZE )
     {
         ERROR("Invalid page size %u for x86_hvm domains",
               ctx->restore.guest_page_size);
         return -1;
     }
+
 #ifdef __i386__
     /* Very large domains (> 1TB) will exhaust virtual address space. */
     if ( ctx->restore.p2m_size > 0x0fffffff )
index c673b2670ca2da82abd6aef8063c403caa88f511..0a5b0016b4dbb419586baab4b633c42714bdfceb 100644 (file)
@@ -145,7 +145,8 @@ static int process_start_info(struct xc_sr_context *ctx,
         ERROR("Start Info pfn %#lx out of range", pfn);
         goto err;
     }
-    else if ( ctx->x86_pv.restore.pfn_types[pfn] != XEN_DOMCTL_PFINFO_NOTAB )
+
+    if ( ctx->x86_pv.restore.pfn_types[pfn] != XEN_DOMCTL_PFINFO_NOTAB )
     {
         ERROR("Start Info pfn %#lx has bad type %u", pfn,
               (ctx->x86_pv.restore.pfn_types[pfn] >>
@@ -275,8 +276,8 @@ static int process_vcpu_basic(struct xc_sr_context *ctx,
             ERROR("GDT frame %u (pfn %#lx) out of range", i, pfn);
             goto err;
         }
-        else if ( (ctx->x86_pv.restore.pfn_types[pfn] !=
-                   XEN_DOMCTL_PFINFO_NOTAB) )
+
+        if ( (ctx->x86_pv.restore.pfn_types[pfn] != XEN_DOMCTL_PFINFO_NOTAB) )
         {
             ERROR("GDT frame %u (pfn %#lx) has bad type %u", i, pfn,
                   (ctx->x86_pv.restore.pfn_types[pfn] >>
@@ -302,10 +303,10 @@ static int process_vcpu_basic(struct xc_sr_context *ctx,
         ERROR("cr3 (pfn %#lx) out of range", pfn);
         goto err;
     }
-    else if ( (ctx->x86_pv.restore.pfn_types[pfn] &
-                XEN_DOMCTL_PFINFO_LTABTYPE_MASK) !=
-              (((xen_pfn_t)ctx->x86_pv.levels) <<
-               XEN_DOMCTL_PFINFO_LTAB_SHIFT) )
+
+    if ( (ctx->x86_pv.restore.pfn_types[pfn] &
+          XEN_DOMCTL_PFINFO_LTABTYPE_MASK) !=
+         (((xen_pfn_t)ctx->x86_pv.levels) << XEN_DOMCTL_PFINFO_LTAB_SHIFT) )
     {
         ERROR("cr3 (pfn %#lx) has bad type %u, expected %u", pfn,
               (ctx->x86_pv.restore.pfn_types[pfn] >>
@@ -334,10 +335,10 @@ static int process_vcpu_basic(struct xc_sr_context *ctx,
             ERROR("cr1 (pfn %#lx) out of range", pfn);
             goto err;
         }
-        else if ( (ctx->x86_pv.restore.pfn_types[pfn] &
-                   XEN_DOMCTL_PFINFO_LTABTYPE_MASK) !=
-                  (((xen_pfn_t)ctx->x86_pv.levels) <<
-                   XEN_DOMCTL_PFINFO_LTAB_SHIFT) )
+
+        if ( (ctx->x86_pv.restore.pfn_types[pfn] &
+              XEN_DOMCTL_PFINFO_LTABTYPE_MASK) !=
+             (((xen_pfn_t)ctx->x86_pv.levels) << XEN_DOMCTL_PFINFO_LTAB_SHIFT) )
         {
             ERROR("cr1 (pfn %#lx) has bad type %u, expected %u", pfn,
                   (ctx->x86_pv.restore.pfn_types[pfn] >>
@@ -542,8 +543,8 @@ static int update_guest_p2m(struct xc_sr_context *ctx)
                   pfn, i);
             goto err;
         }
-        else if ( (ctx->x86_pv.restore.pfn_types[pfn] !=
-                   XEN_DOMCTL_PFINFO_NOTAB) )
+
+        if ( (ctx->x86_pv.restore.pfn_types[pfn] != XEN_DOMCTL_PFINFO_NOTAB) )
         {
             ERROR("pfn (%#lx) for p2m_frame_list[%u] has bad type %u", pfn, i,
                   (ctx->x86_pv.restore.pfn_types[pfn] >>
@@ -692,7 +693,8 @@ static int handle_x86_pv_p2m_frames(struct xc_sr_context *ctx,
               rec->length, sizeof(*data) + sizeof(uint64_t));
         return -1;
     }
-    else if ( data->start_pfn > data->end_pfn )
+
+    if ( data->start_pfn > data->end_pfn )
     {
         ERROR("End pfn in stream (%#x) exceeds Start (%#x)",
               data->end_pfn, data->start_pfn);
@@ -1048,7 +1050,8 @@ static int x86_pv_setup(struct xc_sr_context *ctx)
               dhdr_type_to_str(ctx->restore.guest_type));
         return -1;
     }
-    else if ( ctx->restore.guest_page_size != PAGE_SIZE )
+
+    if ( ctx->restore.guest_page_size != PAGE_SIZE )
     {
         ERROR("Invalid page size %d for x86_pv domains",
               ctx->restore.guest_page_size);