[PATCH 1/1] sandbox: handling out of memory
Simon Glass
sjg at chromium.org
Sun Jun 7 15:45:53 CEST 2020
Hi Heinrich,
On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> assert() only works in debug mode. So checking a successful memory
> allocation should not use assert().
>
Reviewed-by: Simon Glass <sjg at chromium.org>
What sort of environment are you using that returns NULL in this case?
Regards,
Simon
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
> arch/sandbox/cpu/state.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
> index 1f794123b3..34b6fff7e7 100644
> --- a/arch/sandbox/cpu/state.c
> +++ b/arch/sandbox/cpu/state.c
> @@ -378,7 +378,10 @@ int state_init(void)
>
> state->ram_size = CONFIG_SYS_SDRAM_SIZE;
> state->ram_buf = os_malloc(state->ram_size);
> - assert(state->ram_buf);
> + if (!state->ram_buf) {
> + printf("Out of memory\n");
> + os_exit(1);
> + }
>
> state_reset_for_test(state);
> /*
> --
> 2.26.2
>
More information about the U-Boot
mailing list