From: Patrick Delaunay <patrick.delaunay@foss.st.com>
Date: Wed, 10 Mar 2021 09:16:27 +0000 (+0100)
Subject: lmb: add a max parameter in the struct lmb_region
X-Git-Tag: v2025.01-rc5-pxa1908~1906^2~5
X-Git-Url: http://git.dujemihanovic.xyz/img/static/%7B%7B%20%24.Site.BaseURL%20%7D%7Dposts/html/index.html?a=commitdiff_plain;h=00fd8dad4d2ed738d11f29d992dc106bbdf4d68f;p=u-boot.git

lmb: add a max parameter in the struct lmb_region

Add a max parameter in lmb_region struct to handle test
in lmb_add_region without using the MAX_LMB_REGIONS
define.

This patch allows to modify these size independently for
memory of reserved regions in the next patches.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

diff --git a/include/lmb.h b/include/lmb.h
index a3247544c1..f3397c7f73 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -21,6 +21,7 @@ struct lmb_property {
 
 struct lmb_region {
 	unsigned long cnt;
+	unsigned long max;
 	struct lmb_property region[MAX_LMB_REGIONS+1];
 };
 
diff --git a/lib/lmb.c b/lib/lmb.c
index 5cf419f439..a926198d48 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -95,6 +95,9 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1,
 
 void lmb_init(struct lmb *lmb)
 {
+	lmb->memory.max = MAX_LMB_REGIONS;
+	lmb->reserved.max = MAX_LMB_REGIONS;
+
 	lmb->memory.cnt = 0;
 	lmb->reserved.cnt = 0;
 }
@@ -179,7 +182,7 @@ static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, phys_size_t
 
 	if (coalesced)
 		return coalesced;
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt >= rgn->max)
 		return -1;
 
 	/* Couldn't coalesce the LMB, so add it to the sorted table. */