All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] sandbox: handling out of memory
@ 2020-06-04 17:28 Heinrich Schuchardt
  2020-06-07 13:45 ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Heinrich Schuchardt @ 2020-06-04 17:28 UTC (permalink / raw)
  To: u-boot

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 1/1] sandbox: handling out of memory
  2020-06-04 17:28 [PATCH 1/1] sandbox: handling out of memory Heinrich Schuchardt
@ 2020-06-07 13:45 ` Simon Glass
  2020-06-07 14:02   ` Heinrich Schuchardt
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2020-06-07 13:45 UTC (permalink / raw)
  To: u-boot

Hi Heinrich,

On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> assert() only works in debug mode. So checking a successful memory
> allocation should not use assert().
>

Reviewed-by: Simon Glass <sjg@chromium.org>

What sort of environment are you using that returns NULL in this case?

Regards,
Simon


> Signed-off-by: Heinrich Schuchardt <xypron.glpk@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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] sandbox: handling out of memory
  2020-06-07 13:45 ` Simon Glass
@ 2020-06-07 14:02   ` Heinrich Schuchardt
  2020-06-07 16:54     ` Heinrich Schuchardt
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2020-06-07 14:02 UTC (permalink / raw)
  To: u-boot

Am June 7, 2020 1:45:53 PM UTC schrieb Simon Glass <sjg@chromium.org>:
>Hi Heinrich,
>
>On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk@gmx.de>
>wrote:
>>
>> assert() only works in debug mode. So checking a successful memory
>> allocation should not use assert().
>>
>
>Reviewed-by: Simon Glass <sjg@chromium.org>
>
>What sort of environment are you using that returns NULL in this case?

You will get NULL here if mmap() fails. This should happen if your machine has less then 128 MiB left over or you increase the RAM size of the sandbox.

For testing I suggest you increase the sandbox memory size beyond the RAM and swap size of your computer.

Best regards

Heinrich

>
>Regards,
>Simon
>
>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@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
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] sandbox: handling out of memory
  2020-06-07 14:02   ` Heinrich Schuchardt
@ 2020-06-07 16:54     ` Heinrich Schuchardt
  2020-07-06  1:34     ` Simon Glass
  2020-07-06  1:37     ` Simon Glass
  2 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2020-06-07 16:54 UTC (permalink / raw)
  To: u-boot

On 6/7/20 4:02 PM, Heinrich Schuchardt wrote:
> Am June 7, 2020 1:45:53 PM UTC schrieb Simon Glass <sjg@chromium.org>:
>> Hi Heinrich,
>>
>> On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk@gmx.de>
>> wrote:
>>>
>>> assert() only works in debug mode. So checking a successful memory
>>> allocation should not use assert().
>>>
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>
>> What sort of environment are you using that returns NULL in this case?
>
> You will get NULL here if mmap() fails. This should happen if your machine has less then 128 MiB left over or you increase the RAM size of the sandbox.
>
> For testing I suggest you increase the sandbox memory size beyond the RAM and swap size of your computer.
>
> Best regards
>
> Heinrich

An excessive RAM sandbox w/o the patch:

$ ./u-boot
Segmentation fault

with the patch

$ ./u-boot
Out of memory

Best regards

Heinrich

>
>>
>> Regards,
>> Simon
>>
>>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@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
>>>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] sandbox: handling out of memory
  2020-06-07 14:02   ` Heinrich Schuchardt
  2020-06-07 16:54     ` Heinrich Schuchardt
@ 2020-07-06  1:34     ` Simon Glass
  2020-07-06  1:37     ` Simon Glass
  2 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2020-07-06  1:34 UTC (permalink / raw)
  To: u-boot

On 6/7/20 4:02 PM, Heinrich Schuchardt wrote:
> Am June 7, 2020 1:45:53 PM UTC schrieb Simon Glass <sjg@chromium.org>:
>> Hi Heinrich,
>>
>> On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk@gmx.de>
>> wrote:
>>>
>>> assert() only works in debug mode. So checking a successful memory
>>> allocation should not use assert().
>>>
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>
>> What sort of environment are you using that returns NULL in this case?
>
> You will get NULL here if mmap() fails. This should happen if your machine has less then 128 MiB left over or you increase the RAM size of the sandbox.
>
> For testing I suggest you increase the sandbox memory size beyond the RAM and swap size of your computer.
>
> Best regards
>
> Heinrich

An excessive RAM sandbox w/o the patch:

$ ./u-boot
Segmentation fault

with the patch

$ ./u-boot
Out of memory

Best regards

Heinrich

>
>>
>> Regards,
>> Simon
>>
>>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>> ---
>>>  arch/sandbox/cpu/state.c | 5 ++++-
>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>
Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] sandbox: handling out of memory
  2020-06-07 14:02   ` Heinrich Schuchardt
  2020-06-07 16:54     ` Heinrich Schuchardt
  2020-07-06  1:34     ` Simon Glass
@ 2020-07-06  1:37     ` Simon Glass
  2 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2020-07-06  1:37 UTC (permalink / raw)
  To: u-boot

On 6/7/20 4:02 PM, Heinrich Schuchardt wrote:
> Am June 7, 2020 1:45:53 PM UTC schrieb Simon Glass <sjg@chromium.org>:
>> Hi Heinrich,
>>
>> On Thu, 4 Jun 2020 at 11:28, Heinrich Schuchardt <xypron.glpk@gmx.de>
>> wrote:
>>>
>>> assert() only works in debug mode. So checking a successful memory
>>> allocation should not use assert().
>>>
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>
>> What sort of environment are you using that returns NULL in this case?
>
> You will get NULL here if mmap() fails. This should happen if your machine has less then 128 MiB left over or you increase the RAM size of the sandbox.
>
> For testing I suggest you increase the sandbox memory size beyond the RAM and swap size of your computer.
>
> Best regards
>
> Heinrich

An excessive RAM sandbox w/o the patch:

$ ./u-boot
Segmentation fault

with the patch

$ ./u-boot
Out of memory

Best regards

Heinrich

>
>>
>> Regards,
>> Simon
>>
>>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>> ---
>>>  arch/sandbox/cpu/state.c | 5 ++++-
>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>
Applied to u-boot-dm/next, thanks!
Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-06  1:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 17:28 [PATCH 1/1] sandbox: handling out of memory Heinrich Schuchardt
2020-06-07 13:45 ` Simon Glass
2020-06-07 14:02   ` Heinrich Schuchardt
2020-06-07 16:54     ` Heinrich Schuchardt
2020-07-06  1:34     ` Simon Glass
2020-07-06  1:37     ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.