[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
From: |
Alex Bennée |
Subject: |
Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO() |
Date: |
Wed, 05 Apr 2023 14:55:41 +0100 |
User-agent: |
mu4e 1.10.0; emacs 29.0.60 |
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> g_malloc0() can not fail. Use g_try_malloc0() instead.
>
> https://developer-old.gnome.org/glib/stable/glib-Memory-Allocation.html#glib-Memory-Allocation.description
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/i386/nvmm/nvmm-all.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
> index 3c7bdd560f..45fd318d23 100644
> --- a/target/i386/nvmm/nvmm-all.c
> +++ b/target/i386/nvmm/nvmm-all.c
> @@ -942,7 +942,7 @@ nvmm_init_vcpu(CPUState *cpu)
> }
> }
>
> - qcpu = g_malloc0(sizeof(*qcpu));
> + qcpu = g_try_malloc0(sizeof(*qcpu));
> if (qcpu == NULL) {
> error_report("NVMM: Failed to allocate VCPU context.");
> return -ENOMEM;
Why - if we fail to allocate the vCPU context its game over anyway any
established QEMU practice is its ok to assert fail on a malloc when
there isn't enough memory. IOW keep the g_malloc0 and remove the error
handling case.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
- [PATCH 04/14] accel: Destroy HAX vCPU threads once done, (continued)
- [PATCH 04/14] accel: Destroy HAX vCPU threads once done, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 06/14] accel: Use a typedef for struct hax_vcpu_state, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 08/14] accel: Move HAX hThread to accelerator context, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO(), Philippe Mathieu-Daudé, 2023/04/05
- Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO(),
Alex Bennée <=
- [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu(), Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState, Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu(), Philippe Mathieu-Daudé, 2023/04/05
- [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState, Philippe Mathieu-Daudé, 2023/04/05