mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <>
Cc: Ahmad Fatoum <>
Subject: [PATCH v2 2/7] tlsf: ensure malloc pool is aligned
Date: Mon, 11 Sep 2023 17:24:28 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

The struct control_t describing a pool is allocated at its very start
and then directly followed by the first block. To ensure the first block
is suitably aligned, align_up the size in tlsf_size(). So far, TLSF on
32-bit and 64-bit happened to be aligned, so this introduces no
functional change just yet. With upcoming changes to the block header to
increase alignment on 32-bit systems, this realignment will become required.

Signed-off-by: Ahmad Fatoum <>
 common/tlsf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/tlsf.c b/common/tlsf.c
index 3673b424a4c5..784012a1f7ab 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -763,11 +763,11 @@ int tlsf_check_pool(pool_t pool)
 ** Size of the TLSF structures in a given memory block passed to
-** tlsf_create, equal to the size of a control_t
+** tlsf_create, equal to aligned size of a control_t
 size_t tlsf_size(void)
-	return sizeof(control_t);
+	return align_up(sizeof(control_t), ALIGN_SIZE);
 size_t tlsf_align_size(void)

  parent reply	other threads:[~2023-09-11 15:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 15:24 [PATCH v2 0/7] tlsf: use 8-byte alignment for normal malloc allocations Ahmad Fatoum
2023-09-11 15:24 ` [PATCH v2 1/7] tlsf: turn static const variables into compiletime constant expressions Ahmad Fatoum
2023-09-11 15:24 ` Ahmad Fatoum [this message]
2023-09-11 15:24 ` [PATCH v2 3/7] tlsf: fix sizeof(size_t) == sizeof(void *) assumption Ahmad Fatoum
2023-09-11 15:24 ` [PATCH v2 4/7] tlsf: give malloc 8-byte alignment on 32-bit as well Ahmad Fatoum
2023-09-11 15:24 ` [PATCH v2 5/7] common: malloc: ensure alignment is always at least 8 byte Ahmad Fatoum
2023-09-11 15:24 ` [PATCH v2 6/7] test: self: refactor to allow alignment check Ahmad Fatoum
2023-09-11 15:24 ` [PATCH v2 7/7] test: self: malloc: fix memory leaks Ahmad Fatoum
2023-09-26 10:57 ` [PATCH v2 0/7] tlsf: use 8-byte alignment for normal malloc allocations 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:

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

  git send-email \ \ \ \

* 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