Skip to contentSkip to conversation

target: hax: replace g_malloc with g_malloc0

PATCH In review root 2 participants 2 messages Nov 15, 2018

lore
Share & tools
lore

root

author
#0 lore raw

PATCH 1/1 target: hax: replace g_malloc with g_malloc0

From: Li Qiang <[email protected]>

And also the g_malloc doesn't need check return value, remove it.

---
 target/i386/hax-all.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
target/i386/hax-all.c +3 -12
index d2e512856b..a460c605af 100644
@@ -154,13 +154,7 @@ int hax_vcpu_create(int id)
         return 0;
     }
 
-    vcpu = g_malloc(sizeof(struct hax_vcpu_state));
-    if (!vcpu) {
-        fprintf(stderr, "Failed to alloc vcpu state\n");
-        return -ENOMEM;
-    }
-
-    memset(vcpu, 0, sizeof(struct hax_vcpu_state));
+    vcpu = g_malloc0(sizeof(struct hax_vcpu_state));
 
     ret = hax_host_create_vcpu(hax_global.vm->fd, id);
     if (ret) {
@@ -250,11 +244,8 @@ struct hax_vm *hax_vm_create(struct hax_state *hax)
         return hax->vm;
     }
 
-    vm = g_malloc(sizeof(struct hax_vm));
-    if (!vm) {
-        return NULL;
-    }
-    memset(vm, 0, sizeof(struct hax_vm));
+    vm = g_malloc0(sizeof(struct hax_vm));
+
     ret = hax_host_create_vm(hax, &vm_id);
     if (ret) {
         fprintf(stderr, "Failed to create vm %x\n", ret);
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw

Your e-mail From: header is messed up. Please fix.

Quoted 18 lines · root

From: Li Qiang <[email protected]>

And also the g_malloc doesn't need check return value, remove it.

---
 target/i386/hax-all.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
target/i386/hax-all.c +0 -0
index d2e512856b..a460c605af 100644
@@ -154,13 +154,7 @@ int hax_vcpu_create(int id)
         return 0;

target/i386/hax-all.c int hax_vcpu_create(int id) · line 157

Quoted 10 lines
target/i386/hax-all.c +1 -7
     }
 
-    vcpu = g_malloc(sizeof(struct hax_vcpu_state));
-    if (!vcpu) {
-        fprintf(stderr, "Failed to alloc vcpu state\n");
-        return -ENOMEM;
-    }
-
-    memset(vcpu, 0, sizeof(struct hax_vcpu_state));
+    vcpu = g_malloc0(sizeof(struct hax_vcpu_state));

Make that g_new0(struct hax_vcpu_state).

target/i386/hax-all.c struct hax_vm *hax_vm_create(struct hax_state *hax) · line 247

Quoted 13 lines
target/i386/hax-all.c +1 -5
     ret = hax_host_create_vcpu(hax_global.vm->fd, id);
     if (ret) {
@@ -250,11 +244,8 @@ struct hax_vm *hax_vm_create(struct hax_state *hax)
         return hax->vm;
     }
 
-    vm = g_malloc(sizeof(struct hax_vm));
-    if (!vm) {
-        return NULL;
-    }
-    memset(vm, 0, sizeof(struct hax_vm));
+    vm = g_malloc0(sizeof(struct hax_vm));

Likewise.

target/i386/hax-all.c struct hax_vm *hax_vm_create(struct hax_state *hax) · line 251

Quoted 4 lines
target/i386/hax-all.c +1 -0
+
     ret = hax_host_create_vm(hax, &vm_id);
     if (ret) {
         fprintf(stderr, "Failed to create vm %x\n", ret);

With those two changes: