Skip to contentSkip to conversation

xen-hvm.c: Always return -1 when failure occurs in xen_hvm_init()

PATCH Applied Chen Gang 3 participants 9 messages Sep 4, 2014 – Sep 15, 2014

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH v2 1/1 xen-hvm.c: Always return -1 when failure occurs in xen_hvm_init()

When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too.

For simplify thinking, in xen_hvm_init(), also use '-1' instead of all '-errno', since all related upper callers always exit(1) for failure.

It is not a normal function, it does not release related resources when return -1, so need give related comments for it.

It passes common check:

  "./configure --enable-xen && make && make check"
  "echo $? == 0"
---
 xen-hvm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen-hvm.c +4 -5
index 0d09940..2c6285d 100644
@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
     xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
 }
 
+/* return 0 means OK, or -1 means critical issue -- will exit(1) */
 int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
                  MemoryRegion **ram_memory)
 {
@@ -991,15 +992,13 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     state->xce_handle = xen_xc_evtchn_open(NULL, 0);
     if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
         perror("xen: event channel open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->xenstore = xs_daemon_open();
     if (state->xenstore == NULL) {
         perror("xen: xenstore open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->exit.notify = xen_exit_notifier;
@@ -1069,7 +1068,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
-        exit(1);
+        return -1;
     }
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
Signature · 1 line
1.9.3
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Chen Gang

When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too.

For simplify thinking, in xen_hvm_init(), also use '-1' instead of all '-errno', since all related upper callers always exit(1) for failure.

It is not a normal function, it does not release related resources when return -1, so need give related comments for it.

Quoted 7 lines

It passes common check:

  "./configure --enable-xen && make && make check"
  "echo $? == 0"
Quoted 45 lines
 xen-hvm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen-hvm.c +4 -5
index 0d09940..2c6285d 100644
@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
     xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
 }
 
+/* return 0 means OK, or -1 means critical issue -- will exit(1) */
 int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
                  MemoryRegion **ram_memory)
 {
@@ -991,15 +992,13 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     state->xce_handle = xen_xc_evtchn_open(NULL, 0);
     if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
         perror("xen: event channel open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->xenstore = xs_daemon_open();
     if (state->xenstore == NULL) {
         perror("xen: xenstore open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->exit.notify = xen_exit_notifier;
@@ -1069,7 +1068,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
-        exit(1);
+        return -1;
     }
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
Signature · 1 line
1.9.3
Acked-by on v2 1/1
#2 lore raw
In reply to Chen Gang
Quoted 10 lines · Chen Gang

When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too.

For simplify thinking, in xen_hvm_init(), also use '-1' instead of all '-errno', since all related upper callers always exit(1) for failure.

It is not a normal function, it does not release related resources when return -1, so need give related comments for it.

Quoted 7 lines

It passes common check:

  "./configure --enable-xen && make && make check"
  "echo $? == 0"
Quoted 45 lines
 xen-hvm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen-hvm.c +4 -5
index 0d09940..2c6285d 100644
@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
     xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
 }
 
+/* return 0 means OK, or -1 means critical issue -- will exit(1) */
 int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
                  MemoryRegion **ram_memory)
 {
@@ -991,15 +992,13 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     state->xce_handle = xen_xc_evtchn_open(NULL, 0);
     if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
         perror("xen: event channel open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->xenstore = xs_daemon_open();
     if (state->xenstore == NULL) {
         perror("xen: xenstore open");
-        g_free(state);
-        return -errno;
+        return -1;
     }
 
     state->exit.notify = xen_exit_notifier;
@@ -1069,7 +1068,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
-        exit(1);
+        return -1;
     }
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
Signature · 1 line
1.9.3
author
#5 lore raw
Quoted 3 lines · Michael Tokarev

Applied to -trivial, after fixing the commit message to be just a bit more english-like. Thank you!

OK, thank you for your work.

Next, I shall do something related microblaze under Qemu to let it run for microblaze gcc/binutils test, hope I can find additonal patches for it.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#6 lore raw
In reply to Michael Tokarev
Quoted 3 lines · Michael Tokarev

Applied to -trivial, after fixing the commit message to be just a bit more english-like. Thank you!

OK, thank you for your work.

Next, I shall do something related microblaze under Qemu to let it run for microblaze gcc/binutils test, hope I can find additional patches for it.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#7 lore raw
In reply to Michael Tokarev
Quoted 3 lines · Michael Tokarev

Applied to -trivial, after fixing the commit message to be just a bit more english-like. Thank you!

OK, thank you for your work.

Next, I shall do something related microblaze under Qemu to let it run for microblaze gcc/binutils test, hope I can find additonal patches for it.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#8 lore raw
In reply to Michael Tokarev
Quoted 3 lines · Michael Tokarev

Applied to -trivial, after fixing the commit message to be just a bit more english-like. Thank you!

OK, thank you for your work.

Next, I shall do something related microblaze under Qemu to let it run for microblaze gcc/binutils test, hope I can find additional patches for it.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed