diff mbox series

[RFC,1/2] lmb: refactor lmb push and pop functions

Message ID 20241029071846.514559-2-sughosh.ganu@linaro.org
State New
Headers show
Series apple: dart: Add driver specific instance of LMB | expand

Commit Message

Sughosh Ganu Oct. 29, 2024, 7:18 a.m. UTC
The LMB module uses a separate instance of the lmb structure when
running tests. Setting up the correct instance is done using the
lmb_push() and lmb_pop() functions. In addition to pushing and popping
the lmb instances, these functions are also doing some test specific
operations. Move these operations to lmb_test_push() and
lmb_test_pop() functions, so that lmb_push() and lmb_pop() can be
called from elsewhere.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 include/lmb.h  |  4 +++-
 lib/lmb.c      | 20 ++++++++++++++++----
 test/lib/lmb.c | 18 +++++++++---------
 3 files changed, 28 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/include/lmb.h b/include/lmb.h
index e46abf400c6..72d7093023a 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -171,8 +171,10 @@  void lmb_dump_all_force(void);
 void lmb_arch_add_memory(void);
 
 struct lmb *lmb_get(void);
-int lmb_push(struct lmb *store);
+void lmb_push(struct lmb *store);
 void lmb_pop(struct lmb *store);
+int lmb_test_push(struct lmb *store);
+void lmb_test_pop(struct lmb *store);
 
 static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
 {
diff --git a/lib/lmb.c b/lib/lmb.c
index eec99c185ee..2960c05abfc 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -892,12 +892,23 @@  struct lmb *lmb_get(void)
 	return &lmb;
 }
 
+void lmb_push(struct lmb *store)
+{
+	*store = lmb;
+}
+
+void lmb_pop(struct lmb *store)
+{
+	lmb = *store;
+}
+
 #if CONFIG_IS_ENABLED(UNIT_TEST)
-int lmb_push(struct lmb *store)
+int lmb_test_push(struct lmb *store)
 {
 	int ret;
 
-	*store = lmb;
+	lmb_push(store);
+
 	ret = lmb_setup(true);
 	if (ret)
 		return ret;
@@ -905,10 +916,11 @@  int lmb_push(struct lmb *store)
 	return 0;
 }
 
-void lmb_pop(struct lmb *store)
+void lmb_test_pop(struct lmb *store)
 {
 	alist_uninit(&lmb.free_mem);
 	alist_uninit(&lmb.used_mem);
-	lmb = *store;
+
+	lmb_pop(store);
 }
 #endif /* UNIT_TEST */
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index b2c54fb4bcb..64e619eff22 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -63,7 +63,7 @@  static int setup_lmb_test(struct unit_test_state *uts, struct lmb *store,
 {
 	struct lmb *lmb;
 
-	ut_assertok(lmb_push(store));
+	ut_assertok(lmb_test_push(store));
 	lmb = lmb_get();
 	*mem_lstp = &lmb->free_mem;
 	*used_lstp = &lmb->used_mem;
@@ -194,7 +194,7 @@  static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
 		ut_asserteq(mem[0].size, ram_size);
 	}
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -293,7 +293,7 @@  static int test_bigblock(struct unit_test_state *uts, const phys_addr_t ram)
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000,
 		   0, 0, 0, 0);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -373,7 +373,7 @@  static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram,
 	ut_asserteq(ret, 0);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -446,7 +446,7 @@  static int lib_test_lmb_at_0(struct unit_test_state *uts)
 	ut_asserteq(ret, 0);
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -499,7 +499,7 @@  static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts)
 	ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000,
 		   0, 0, 0, 0);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -619,7 +619,7 @@  static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 		ut_asserteq(ret, 0);
 	}
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -691,7 +691,7 @@  static int test_get_unreserved_size(struct unit_test_state *uts,
 	s = lmb_get_free_size(ram_end - 4);
 	ut_asserteq(s, 4);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }
@@ -797,7 +797,7 @@  static int lib_test_lmb_flags(struct unit_test_state *uts)
 	ut_asserteq(lmb_is_nomap(&used[1]), 0);
 	ut_asserteq(lmb_is_nomap(&used[2]), 1);
 
-	lmb_pop(&store);
+	lmb_test_pop(&store);
 
 	return 0;
 }