target: hax: replace g_malloc with g_new0
PATCH 1/1 target: hax: replace g_malloc with g_new0
And also the g_malloc doesn't need check return value, remove it.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Reviewed-by Markus Armbruster <[email protected]>
Signed-off-by Li Qiang <[email protected]>
--- target/i386/hax-all.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
target/i386/hax-all.c +3 -12
@@ -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_new0(struct hax_vcpu_state, 1); 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_new0(struct hax_vm, 1); + 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
Quoted 36 lines · Li Qiang
And also the
g_mallocdoesn't need check return value, remove it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Li Qiang <[email protected]>--- target/i386/hax-all.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)target/i386/hax-all.c +1
-7@@ -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_new0(struct hax_vcpu_state, 1); 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; }
target/i386/hax-all.c struct hax_vm *hax_vm_create(struct hax_state *hax) · line 251
Quoted 10 lines
target/i386/hax-all.c +2
-5- vm =g_malloc (sizeof (struct hax_vm )); -if (!vm) { -return NULL ; - } -memset (vm,0 ,sizeof (struct hax_vm )); + vm = g_new0(struct hax_vm, 1); + ret =hax_host_create_vm (hax, &vm_id);if (ret) {fprintf (stderr,"Failed to create vm %x\n" , ret);
Reviewed-by Laurent Vivier <[email protected]>
Quoted 8 lines · Li Qiang
And also the
g_mallocdoesn't need check return value, remove it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Li Qiang <[email protected]>
Reviewed-by Alex Bennée <[email protected]>
Quoted 27 lines
--- target/i386/hax-all.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)target/i386/hax-all.c +1
-7@@ -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_new0(struct hax_vcpu_state, 1); 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; }
target/i386/hax-all.c struct hax_vm *hax_vm_create(struct hax_state *hax) · line 251
Quoted 10 lines
target/i386/hax-all.c +2
-5- vm =g_malloc (sizeof (struct hax_vm )); -if (!vm) { -return NULL ; - } -memset (vm,0 ,sizeof (struct hax_vm )); + vm = g_new0(struct hax_vm, 1); + ret =hax_host_create_vm (hax, &vm_id);if (ret) {fprintf (stderr,"Failed to create vm %x\n" , ret);
--
Alex Bennée
Laurent Vivier
AppliedQuoted 12 lines · Li Qiang
And also the
g_mallocdoesn't need check return value, remove it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Li Qiang <[email protected]>--- target/i386/hax-all.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
Applied to my trivial-patches branch.
Thanks,
Laurent