mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] sandbox: libc_malloc: populate barebox errno on error
Date: Thu, 23 Nov 2023 08:20:42 +0100	[thread overview]
Message-ID: <20231123072042.GD3359458@pengutronix.de> (raw)
In-Reply-To: <20231122170007.3849506-1-a.fatoum@pengutronix.de>

On Wed, Nov 22, 2023 at 06:00:06PM +0100, Ahmad Fatoum wrote:
> TLSF already populates errno on errors, so do likewise for the
> allocators that don't.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  arch/sandbox/os/libc_malloc.c | 28 ++++++++++++++++++++++++----
>  1 file changed, 24 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c
> index 74e3e2680585..975c41b0ec49 100644
> --- a/arch/sandbox/os/libc_malloc.c
> +++ b/arch/sandbox/os/libc_malloc.c
> @@ -6,18 +6,30 @@
>  #include <stdlib.h>
>  #include <malloc.h>
>  
> +#define BAREBOX_ENOMEM 12
> +extern int barebox_errno;
> +
>  void barebox_malloc_stats(void)
>  {
>  }
>  
>  void *barebox_memalign(size_t alignment, size_t bytes)
>  {
> -	return memalign(alignment, bytes);
> +	void *mem = memalign(alignment, bytes);
> +	if (!mem)
> +		barebox_errno = BAREBOX_ENOMEM;
> +
> +	return mem;
>  }
>  
>  void *barebox_malloc(size_t size)
>  {
> -	return malloc(size);
> +
> +	void *mem = malloc(size);
> +	if (!mem)
> +		barebox_errno = BAREBOX_ENOMEM;
> +
> +	return mem;
>  }
>  
>  void barebox_free(void *ptr)
> @@ -27,10 +39,18 @@ void barebox_free(void *ptr)
>  
>  void *barebox_realloc(void *ptr, size_t size)
>  {
> -	return realloc(ptr, size);
> +	void *mem = realloc(ptr, size);
> +	if (!mem)
> +		barebox_errno = BAREBOX_ENOMEM;
> +
> +	return mem;
>  }
>  
>  void *barebox_calloc(size_t n, size_t elem_size)
>  {
> -	return calloc(n, elem_size);
> +	void *mem = calloc(n, elem_size);
> +	if (!mem)
> +		barebox_errno = BAREBOX_ENOMEM;
> +
> +	return mem;
>  }
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      parent reply	other threads:[~2023-11-23  7:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 17:00 Ahmad Fatoum
2023-11-22 17:00 ` [PATCH 2/2] dlmalloc: populate " Ahmad Fatoum
2023-11-23  7:20 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231123072042.GD3359458@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox