[PATCH 2/2] lmb: Simplify lmb_should_notify usage

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Oct 23 17:22:01 CEST 2024


We never call lmb_map_update_notify() without checking the result of
lmb_should_notify(). Instead of running that function everytime fold it
in there and add the additional flags parameter

Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
---
 lib/lmb.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 8ce58fcb9224..69001ad57373 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -40,7 +40,7 @@ static bool lmb_should_notify(enum lmb_flags flags)
 
 static int __maybe_unused lmb_map_update_notify(phys_addr_t addr,
 						phys_size_t size,
-						u8 op)
+						u8 op, enum lmb_flags flags)
 {
 	u64 efi_addr;
 	u64 pages;
@@ -51,6 +51,9 @@ static int __maybe_unused lmb_map_update_notify(phys_addr_t addr,
 		return -1;
 	}
 
+	if (!lmb_should_notify(flags))
+		return 0;
+
 	efi_addr = (uintptr_t)map_sysmem(addr, 0);
 	pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK));
 	efi_addr &= ~EFI_PAGE_MASK;
@@ -64,9 +67,9 @@ static int __maybe_unused lmb_map_update_notify(phys_addr_t addr,
 		log_err("%s: LMB Map notify failure %lu\n", __func__,
 			status & ~EFI_ERROR_MASK);
 		return -1;
-	} else {
-		return 0;
 	}
+
+	return 0;
 }
 
 static void lmb_print_region_flags(enum lmb_flags flags)
@@ -490,10 +493,7 @@ long lmb_add(phys_addr_t base, phys_size_t size)
 	if (ret)
 		return ret;
 
-	if (lmb_should_notify(LMB_NONE))
-		return lmb_map_update_notify(base, size, MAP_OP_ADD);
-
-	return 0;
+	return lmb_map_update_notify(base, size, MAP_OP_ADD, LMB_NONE);
 }
 
 static long _lmb_free(phys_addr_t base, phys_size_t size)
@@ -566,10 +566,7 @@ long lmb_free_flags(phys_addr_t base, phys_size_t size,
 	if (ret < 0)
 		return ret;
 
-	if (lmb_should_notify(flags))
-		return lmb_map_update_notify(base, size, MAP_OP_FREE);
-
-	return ret;
+	return lmb_map_update_notify(base, size, MAP_OP_FREE, flags);
 }
 
 long lmb_free(phys_addr_t base, phys_size_t size)
@@ -586,10 +583,7 @@ long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags)
 	if (ret)
 		return ret;
 
-	if (lmb_should_notify(flags))
-		return lmb_map_update_notify(base, size, MAP_OP_RESERVE);
-
-	return ret;
+	return lmb_map_update_notify(base, size, MAP_OP_RESERVE, flags);
 }
 
 long lmb_reserve(phys_addr_t base, phys_size_t size)
@@ -621,7 +615,6 @@ static phys_addr_t lmb_align_down(phys_addr_t addr, phys_size_t size)
 static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align,
 				    phys_addr_t max_addr, enum lmb_flags flags)
 {
-	u8 op;
 	int ret;
 	long i, rgn;
 	phys_addr_t base = 0;
@@ -654,13 +647,11 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align,
 							 size, flags))
 					return 0;
 
-				if (lmb_should_notify(flags)) {
-					op = MAP_OP_RESERVE;
-					ret = lmb_map_update_notify(base, size,
-								    op);
-					if (ret)
-						return ret;
-				}
+				ret = lmb_map_update_notify(base, size,
+							    MAP_OP_RESERVE,
+							    flags);
+				if (ret)
+					return ret;
 
 				return base;
 			}
-- 
2.45.2



More information about the U-Boot mailing list