[PATCH 5/7] lmb: Tidy up lmb_overlaps_region()

Simon Glass sjg at chromium.org
Wed Aug 23 15:42:01 CEST 2023


Add a comment to define what this returns. Return a specific error when
no overlap is found.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 lib/lmb.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index bf30e0dc90b2..5f2ea45c3ba9 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -387,6 +387,13 @@ int lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size)
 	return lmb_reserve_flags(lmb, base, size, LMB_NONE);
 }
 
+/**
+ * lmb_overlaps_region() - Check if a region overlaps a given base/size
+ *
+ * @base:	base address of the memory region
+ * @size:	size of the memory region
+ * Returns: Region number of overlapping region, if found, else -ENOENT
+ */
 static int lmb_overlaps_region(struct lmb_region *rgn, phys_addr_t base,
 			       phys_size_t size)
 {
@@ -396,10 +403,10 @@ static int lmb_overlaps_region(struct lmb_region *rgn, phys_addr_t base,
 		phys_addr_t rgnbase = rgn->region[i].base;
 		phys_size_t rgnsize = rgn->region[i].size;
 		if (lmb_addrs_overlap(base, size, rgnbase, rgnsize))
-			break;
+			return i;
 	}
 
-	return i < rgn->cnt ? i : -1;
+	return -ENOENT;
 }
 
 phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align)
-- 
2.42.0.rc1.204.g551eb34607-goog



More information about the U-Boot mailing list