From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] dlmalloc: populate errno on error
Date: Wed, 22 Nov 2023 18:00:07 +0100 [thread overview]
Message-ID: <20231122170007.3849506-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231122170007.3849506-1-a.fatoum@pengutronix.de>
TLSF already populates errno on errors, so do likewise for the
allocators that don't.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/dlmalloc.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index c634fb1997a5..c41487d54b4a 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1,5 +1,6 @@
#include <config.h>
+#include <errno.h>
#include <malloc.h>
#include <string.h>
#include <memory.h>
@@ -1167,8 +1168,10 @@ void *malloc(size_t bytes)
INTERNAL_SIZE_T nb;
- if ((long) bytes < 0)
+ if ((long) bytes < 0) {
+ errno = ENOMEM;
return NULL;
+ }
nb = request2size(bytes); /* padded request size; */
@@ -1322,8 +1325,10 @@ void *malloc(size_t bytes)
if ((remainder_size = chunksize (top) - nb) < (long) MINSIZE) {
/* Try to extend */
malloc_extend_top(nb);
- if ((remainder_size = chunksize(top) - nb) < (long) MINSIZE)
+ if ((remainder_size = chunksize(top) - nb) < (long) MINSIZE) {
+ errno = ENOMEM;
return NULL; /* propagate failure */
+ }
}
victim = top;
@@ -1487,8 +1492,10 @@ void *realloc(void *oldmem, size_t bytes)
}
#endif
- if ((long)bytes < 0)
+ if ((long)bytes < 0) {
+ errno = ENOMEM;
return NULL;
+ }
/* realloc of null is supposed to be same as malloc */
if (!oldmem)
@@ -1654,8 +1661,10 @@ void *memalign(size_t alignment, size_t bytes)
mchunkptr remainder; /* spare room at end to split off */
long remainder_size; /* its size */
- if ((long) bytes < 0)
+ if ((long) bytes < 0) {
+ errno = ENOMEM;
return NULL;
+ }
/* If need less alignment than we give anyway, just relay to malloc */
@@ -1737,8 +1746,10 @@ void *calloc(size_t n, size_t elem_size)
mchunkptr oldtop = top;
INTERNAL_SIZE_T oldtopsize = chunksize(top);
- if ((long)n < 0)
+ if ((long)n < 0) {
+ errno = ENOMEM;
return NULL;
+ }
mem = malloc(sz);
--
2.39.2
next prev parent reply other threads:[~2023-11-22 17:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 17:00 [PATCH 1/2] sandbox: libc_malloc: populate barebox " Ahmad Fatoum
2023-11-22 17:00 ` Ahmad Fatoum [this message]
2023-11-23 7:20 ` Sascha Hauer
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=20231122170007.3849506-2-a.fatoum@pengutronix.de \
--to=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