Skip to contentSkip to conversation

libxl: fix libxl__build_hvm error code return path

PATCH Superseded Wei Liu 3 participants 4 messages Aug 11, 2015 – Aug 12, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libxl: fix libxl__build_hvm error code return path

In 25652f23 ("tools/libxl: detect and avoid conflicts with RDM"), new code was added to use rc to store libxl function call return value, which complied to libxl coding style. That patch, however, didn't change other locations where return value was stored in ret. In the end libxl__build_hvm could return 0 when it failed.

Explicitly set rc to ERROR_FAIL in all error paths to fix this.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Roger Pau Monne <[email protected]>

---
 tools/libxl/libxl_dom.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/libxl/libxl_dom.c +12 -2
index e1f11a3..17ae4bd 100644
@@ -966,12 +966,19 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         ret = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, &args);
         if (ret) {
             LOGEV(ERROR, ret, "hvm build vmemranges failed");
+            rc = ERROR_FAIL;
             goto out;
         }
         ret = libxl__vnuma_config_check(gc, info, state);
-        if (ret) goto out;
+        if (ret) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
         ret = set_vnuma_info(gc, domid, info, state);
-        if (ret) goto out;
+        if (ret) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
 
         args.nr_vmemranges = state->num_vmemranges;
         args.vmemranges = libxl__malloc(gc, sizeof(*args.vmemranges) *
@@ -994,6 +1001,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
     ret = xc_hvm_build(ctx->xch, domid, &args);
     if (ret) {
         LOGEV(ERROR, ret, "hvm building failed");
+        rc = ERROR_FAIL;
         goto out;
     }
 
@@ -1008,12 +1016,14 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
                                state->console_domid);
     if (ret) {
         LOGEV(ERROR, ret, "hvm build set params failed");
+        rc = ERROR_FAIL;
         goto out;
     }
 
     ret = hvm_build_set_xs_values(gc, domid, &args);
     if (ret) {
         LOG(ERROR, "hvm build set xenstore values failed (ret=%d)", ret);
+        rc = ERROR_FAIL;
         goto out;
     }
 
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Wei Liu

In 25652f23 ("tools/libxl: detect and avoid conflicts with RDM"), new code was added to use rc to store libxl function call return value, which complied to libxl coding style. That patch, however, didn't change other locations where return value was stored in ret. In the end libxl__build_hvm could return 0 when it failed.

Explicitly set rc to ERROR_FAIL in all error paths to fix this.

You missed the path from libxl__domain_firmware, which incorrectly relies on rc being already initialised by the declaration (which per CODING_STYLE ought to be removed too).

However perhaps you prefer to leave those other two hunks until 4.7 and this patch is at least an improvement of sorts so:

author
#2 lore raw
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Wei Liu

In 25652f23 ("tools/libxl: detect and avoid conflicts with RDM"), new code was added to use rc to store libxl function call return value, which complied to libxl coding style. That patch, however, didn't change other locations where return value was stored in ret. In the end libxl__build_hvm could return 0 when it failed.

Explicitly set rc to ERROR_FAIL in all error paths to fix this.

Quoted 9 lines
Quoted 1 line

You missed the path from libxl__domain_firmware, which incorrectly relies on rc being already initialised by the declaration (which per CODING_STYLE ought to be removed too).

However perhaps you prefer to leave those other two hunks until 4.7 and this patch is at least an improvement of sorts so:

Yes. Roger already has a patch for 4.7 to fix error handling in this function.

Quoted 1 line

Thanks

#3 lore raw
In reply to Wei Liu

Wei Liu writes ("[PATCH for-4.6] libxl: fix libxl__build_hvm error code return path"):

Quoted 7 lines

In 25652f23 ("tools/libxl: detect and avoid conflicts with RDM"), new code was added to use rc to store libxl function call return value, which complied to libxl coding style. That patch, however, didn't change other locations where return value was stored in ret. In the end libxl__build_hvm could return 0 when it failed.

Explicitly set rc to ERROR_FAIL in all error paths to fix this.

...

Quoted 2 lines
         ret = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, &args);
         if (ret) {

Why not change all the assignemnts to ret to assignments to rc, and abolish ret ?

Quoted 2 lines
             LOGEV(ERROR, ret, "hvm build vmemranges failed");

+ rc = ERROR_FAIL;

Certainly this is wrong because it smashes all errors into ERROR_FAIL.

Ian.