mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/6] dummy_malloc: fail allocations exceeding MALLOC_MAX_SIZE
Date: Thu, 20 Feb 2025 21:30:31 +0100	[thread overview]
Message-ID: <20250220203032.3350247-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250220203032.3350247-1-a.fatoum@pengutronix.de>

For uniformity with the proper allocators, let's observe the same
maximum allocation size they do.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/dummy_malloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index 140ba314272a..4973f35650ab 100644
--- a/common/dummy_malloc.c
+++ b/common/dummy_malloc.c
@@ -11,8 +11,10 @@ void malloc_stats(void)
 
 void *memalign(size_t alignment, size_t bytes)
 {
-	void *mem = sbrk(bytes + alignment);
+	void *mem = NULL;
 
+	if (alignment <= MALLOC_MAX_SIZE && bytes <= MALLOC_MAX_SIZE)
+		mem = sbrk(bytes + alignment);
 	if (!mem) {
 		errno = ENOMEM;
 		return NULL;
-- 
2.39.5




  parent reply	other threads:[~2025-02-20 20:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 20:30 [PATCH 1/6] malloc: define a maximum malloc size Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 2/6] tlsf: fail allocations exceeding MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 3/6] dlmalloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 4/6] sandbox: libc_malloc: " Ahmad Fatoum
2025-02-20 20:30 ` Ahmad Fatoum [this message]
2025-02-20 20:30 ` [PATCH 6/6] test: self: malloc: adapt to addition of MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-21 12:20 ` [PATCH 1/6] malloc: define a maximum malloc size 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=20250220203032.3350247-5-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