Skip to contentSkip to conversation

fixup! tlsf: support on-demand requesting memory from external store

PATCH Applied Ahmad Fatoum 2 participants 2 messages Oct 15, 2025 – Oct 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fixup! tlsf: support on-demand requesting memory from external store

tlsf: fix misaccounting in request_store feature

A TLSF pool itself has overhead in the form of tlsf_pool_overhead() that's distinct from the struct pool_entry. Adding a helper that returns this total overhead allows us also to use roundup_pow_of_two(), which previously issues a warning on clang about sizeof(sizeof(...)) looking strange.

Another issues is that request_store was not explicitly zeroed leading to issues on OOM situations, which is remedied as well.

---
 common/tlsf.c        | 1 +
 common/tlsf_malloc.c | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
common/tlsf.c +1 -0
index 3c72b41c0385..e7f1b8354f02 100644
@@ -654,6 +654,7 @@ static void control_construct(control_t* control)
 	control->block_null.next_free = &control->block_null;
 	control->block_null.prev_free = &control->block_null;
 
+	control->request_store = NULL;
 	control->fl_bitmap = 0;
 	for (i = 0; i < FL_INDEX_COUNT; ++i)
 	{
common/tlsf_malloc.c +6 -1
index d3b665a2fc40..9d55014117f0 100644
@@ -27,6 +27,11 @@ struct pool_entry {
 
 static LIST_HEAD(mem_pool_list);
 
+static inline size_t mem_pool_overhead(void)
+{
+	return sizeof(struct pool_entry) + tlsf_pool_overhead();
+}
+
 void *malloc(size_t bytes)
 {
 	void *mem;
@@ -132,7 +137,7 @@ static void tlsf_request_store(tlsf_t tlsf, size_t bytes)
 {
 	size_t size;
 
-	size = __roundup_pow_of_two(bytes + sizeof(struct pool_entry));
+	size = roundup_pow_of_two(bytes + mem_pool_overhead());
 
 	malloc_request_store(max_t(size_t, SZ_8M, size));
 }
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 9 lines · Ahmad Fatoum

tlsf: fix misaccounting in request_store feature

A TLSF pool itself has overhead in the form of tlsf_pool_overhead() that's distinct from the struct pool_entry. Adding a helper that returns this total overhead allows us also to use roundup_pow_of_two(), which previously issues a warning on clang about sizeof(sizeof(...)) looking strange.

[...]

Applied, thanks!

[1/1] fixup! tlsf: support on-demand requesting memory from external store

      https://git.pengutronix.de/cgit/barebox/commit/?id=78cd84652672 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>