Skip to contentSkip to conversation

tools/libxc: Adjust error handling in map_p2m_list() to fix CentOS 7 build

PATCH In review Andrew Cooper 3 participants 3 messages Jan 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/libxc: Adjust error handling in map_p2m_list() to fix CentOS 7 build

The "goto err;" for malloc() error handling would cause the cleanup code to use 'ptes' before it had been initialised, and causing a build failure because of -Werror=maybe-uninitialised.

Use "goto err;" consistently for all error handling.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

---
 tools/libxc/xc_sr_save_x86_pv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/libxc/xc_sr_save_x86_pv.c +5 -5
index 4deb58f..4a29460 100644
@@ -316,8 +316,8 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
     xc_interface *xch = ctx->xch;
     xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
     xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
-    uint64_t *ptes;
-    xen_pfn_t *mfns;
+    uint64_t *ptes = NULL;
+    xen_pfn_t *mfns = NULL;
     unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx, saved_idx;
     int rc = -1;
 
@@ -327,7 +327,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
     {
         ERROR("Bad p2m_cr3 value %#" PRIx64, p2m_cr3);
         errno = ERANGE;
-        return -1;
+        goto err;
     }
 
     get_p2m_generation(ctx);
@@ -350,7 +350,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
             ERROR("Bad virtual p2m address range %#" PRIx64 "-%#" PRIx64,
                   p2m_vaddr, p2m_end);
             errno = ERANGE;
-            return -1;
+            goto err;
         }
     }
     else
@@ -363,7 +363,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
             ERROR("Bad virtual p2m address range %#" PRIx64 "-%#" PRIx64,
                   p2m_vaddr, p2m_end);
             errno = ERANGE;
-            return -1;
+            goto err;
         }
     }
 
Signature · 1 line
2.1.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Andrew Cooper

The "goto err;" for malloc() error handling would cause the cleanup code to use 'ptes' before it had been initialised, and causing a build failure because of -Werror=maybe-uninitialised.

Use "goto err;" consistently for all error handling.

Quoted 52 lines

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

---
 tools/libxc/xc_sr_save_x86_pv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/libxc/xc_sr_save_x86_pv.c +5 -5
index 4deb58f..4a29460 100644
@@ -316,8 +316,8 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
     xc_interface *xch = ctx->xch;
     xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
     xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
-    uint64_t *ptes;
-    xen_pfn_t *mfns;
+    uint64_t *ptes = NULL;
+    xen_pfn_t *mfns = NULL;
     unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx, saved_idx;
     int rc = -1;
 
@@ -327,7 +327,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
     {
         ERROR("Bad p2m_cr3 value %#" PRIx64, p2m_cr3);
         errno = ERANGE;
-        return -1;
+        goto err;
     }
 
     get_p2m_generation(ctx);
@@ -350,7 +350,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
             ERROR("Bad virtual p2m address range %#" PRIx64 "-%#" PRIx64,
                   p2m_vaddr, p2m_end);
             errno = ERANGE;
-            return -1;
+            goto err;
         }
     }
     else
@@ -363,7 +363,7 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
             ERROR("Bad virtual p2m address range %#" PRIx64 "-%#" PRIx64,
                   p2m_vaddr, p2m_end);
             errno = ERANGE;
-            return -1;
+            goto err;
         }
     }
 
#2 lore raw
Quoted 11 lines · Juergen Gross
Quoted 8 lines · Andrew Cooper

The "goto err;" for malloc() error handling would cause the cleanup code
to use 'ptes' before it had been initialised, and causing a build failure because of -Werror=maybe-uninitialised.

Use "goto err;" consistently for all error handling.

Acked, applied, thanks.