[RFC PATCH 5/7] lmb: Replace lmb_alloc_addr() with lmb_alloc_addr_flags()

Ilias Apalodimas ilias.apalodimas at linaro.org
Sun Dec 8 11:52:08 CET 2024


lmb_alloc_addr() is just calling lmb_alloc_addr_flags() with LMB_NONE.
There's not much we gain from this abstraction, so let's remove the
former and make the code a bit easier to follow.

The code size increase is minimal - e.g for sandbox which includes all
of the LMB tests

add/remove: 0/1 grow/shrink: 5/0 up/down: 33/-4 (29)
Function                                     old     new   delta
test_alloc_addr                             2939    2963     +24
wget_handler                                1530    1533      +3
tftp_handler                                1190    1192      +2
do_spi_flash                                3150    3152      +2
_fs_read.lto_priv                            331     333      +2
lmb_alloc_addr                                 4       -      -4
Total: Before=2492734, After=2492763, chg +0.00%

Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
---
 fs/fs.c        |  2 +-
 include/lmb.h  |  3 +--
 lib/lmb.c      |  9 ---------
 test/lib/lmb.c | 28 +++++++++++++++-------------
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 21a23efd932d..b7d422eaf0d1 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -554,7 +554,7 @@ static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
 
 	lmb_dump_all();
 
-	if (lmb_alloc_addr(addr, read_len) == addr)
+	if (lmb_alloc_addr_flags(addr, read_len, LMB_NONE) == addr)
 		return 0;
 
 	log_err("** Reading file would overwrite reserved memory **\n");
diff --git a/include/lmb.h b/include/lmb.h
index 54af5b0e4b44..4e8e4f23e279 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -94,7 +94,6 @@ long lmb_reserve_flags(phys_addr_t base, phys_size_t size,
 		       enum lmb_flags flags);
 phys_addr_t lmb_alloc(phys_size_t size, ulong align);
 phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr);
-phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size);
 phys_size_t lmb_get_free_size(phys_addr_t addr);
 
 phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align,
@@ -152,7 +151,7 @@ void lmb_pop(struct lmb *store);
 
 static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
 {
-	return lmb_alloc_addr(addr, len) == addr ? 0 : -1;
+	return lmb_alloc_addr_flags(addr, len, LMB_NONE) == addr ? 0 : -1;
 }
 
 /**
diff --git a/lib/lmb.c b/lib/lmb.c
index 56e005308dde..6dbdd81bd7d8 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -815,15 +815,6 @@ static phys_addr_t _lmb_alloc_addr(phys_addr_t base, phys_size_t size,
 	return 0;
 }
 
-/*
- * Try to allocate a specific address range: must be in defined memory but not
- * reserved
- */
-phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size)
-{
-	return _lmb_alloc_addr(base, size, LMB_NONE);
-}
-
 /**
  * lmb_alloc_addr_flags() - Allocate specified memory address with specified attributes
  * @base: Base Address requested
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index 0f7052224c10..49857cb3fd4b 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -560,22 +560,24 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 		   alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
 
 	/* allocate blocks */
-	a = lmb_alloc_addr(ram, alloc_addr_a - ram);
+	a = lmb_alloc_addr_flags(ram, alloc_addr_a - ram, LMB_NONE);
 	ut_asserteq(a, ram);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, ram, 0x8010000,
 		   alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
-	b = lmb_alloc_addr(alloc_addr_a + 0x10000,
-			   alloc_addr_b - alloc_addr_a - 0x10000);
+	b = lmb_alloc_addr_flags(alloc_addr_a + 0x10000,
+				 alloc_addr_b - alloc_addr_a - 0x10000,
+				 LMB_NONE);
 	ut_asserteq(b, alloc_addr_a + 0x10000);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x10010000,
 		   alloc_addr_c, 0x10000, 0, 0);
-	c = lmb_alloc_addr(alloc_addr_b + 0x10000,
-			   alloc_addr_c - alloc_addr_b - 0x10000);
+	c = lmb_alloc_addr_flags(alloc_addr_b + 0x10000,
+				 alloc_addr_c - alloc_addr_b - 0x10000,
+				 LMB_NONE);
 	ut_asserteq(c, alloc_addr_b + 0x10000);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
 		   0, 0, 0, 0);
-	d = lmb_alloc_addr(alloc_addr_c + 0x10000,
-			   ram_end - alloc_addr_c - 0x10000);
+	d = lmb_alloc_addr_flags(alloc_addr_c + 0x10000,
+				 ram_end - alloc_addr_c - 0x10000, LMB_NONE);
 	ut_asserteq(d, alloc_addr_c + 0x10000);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size,
 		   0, 0, 0, 0);
@@ -591,7 +593,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 
 	/* allocate at 3 points in free range */
 
-	d = lmb_alloc_addr(ram_end - 4, 4);
+	d = lmb_alloc_addr_flags(ram_end - 4, 4, LMB_NONE);
 	ut_asserteq(d, ram_end - 4);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
 		   d, 4, 0, 0);
@@ -600,7 +602,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
 		   0, 0, 0, 0);
 
-	d = lmb_alloc_addr(ram_end - 128, 4);
+	d = lmb_alloc_addr_flags(ram_end - 128, 4, LMB_NONE);
 	ut_asserteq(d, ram_end - 128);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
 		   d, 4, 0, 0);
@@ -609,7 +611,7 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
 		   0, 0, 0, 0);
 
-	d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4);
+	d = lmb_alloc_addr_flags(alloc_addr_c + 0x10000, 4, LMB_NONE);
 	ut_asserteq(d, alloc_addr_c + 0x10000);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010004,
 		   0, 0, 0, 0);
@@ -624,18 +626,18 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + 0x8000000,
 		   0x10010000, 0, 0, 0, 0);
 
-	d = lmb_alloc_addr(ram, 4);
+	d = lmb_alloc_addr_flags(ram, 4, LMB_NONE);
 	ut_asserteq(d, ram);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, d, 4,
 		   ram + 0x8000000, 0x10010000, 0, 0);
 
 	/* check that allocating outside memory fails */
 	if (ram_end != 0) {
-		ret = lmb_alloc_addr(ram_end, 1);
+		ret = lmb_alloc_addr_flags(ram_end, 1, LMB_NONE);
 		ut_asserteq(ret, 0);
 	}
 	if (ram != 0) {
-		ret = lmb_alloc_addr(ram - 1, 1);
+		ret = lmb_alloc_addr_flags(ram - 1, 1, LMB_NONE);
 		ut_asserteq(ret, 0);
 	}
 
-- 
2.45.2



More information about the U-Boot mailing list