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: Richard Weinberger <richard@nod.at>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/6] malloc: define a maximum malloc size
Date: Thu, 20 Feb 2025 21:30:27 +0100	[thread overview]
Message-ID: <20250220203032.3350247-1-a.fatoum@pengutronix.de> (raw)

TLSF and dlmalloc each already enforce a maximum allocation size.

Let's define SZ_1G as common maximum allocation size in preparation
for aligning all allocators to observe it.

The intention is to make code easier to reason about and as extra
hardening against possible, yet undiscovered, allocator bugs.

Suggested-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/malloc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/malloc.h b/include/malloc.h
index 7bee03dab236..c38726342c08 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,6 +5,9 @@
 #include <linux/compiler.h>
 #include <types.h>
 
+#define MALLOC_SHIFT_MAX	30
+#define MALLOC_MAX_SIZE		(1UL << MALLOC_SHIFT_MAX)
+
 #if IN_PROPER
 void *malloc(size_t) __alloc_size(1);
 size_t malloc_usable_size(void *);
-- 
2.39.5




             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 Ahmad Fatoum [this message]
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 ` [PATCH 5/6] dummy_malloc: " Ahmad Fatoum
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-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=richard@nod.at \
    /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