Re: [PATCH 06/39] lmb: Seperate __lmb_find_base() from __lmb_alloc_base()

Previous thread: [PATCH tip/core/urgent] rcu: updates for RCU lockdep by Paul E. McKenney on Thursday, April 8, 2010 - 10:47 pm. (26 messages)

Next thread: [PATCH 15/39] lmb: Add lmb_find_area_node() by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (3 messages)
From: Yinghai Lu
Date: Thursday, April 8, 2010 - 11:03 pm

So We can construct one generic __find_lmb_area() later

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 mm/lmb.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/mm/lmb.c b/mm/lmb.c
index 65b62dc..392d805 100644
--- a/mm/lmb.c
+++ b/mm/lmb.c
@@ -393,7 +393,7 @@ u64 __init lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 	return alloc;
 }
 
-u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
+static u64 __init __lmb_find_base(u64 size, u64 align, u64 max_addr)
 {
 	long i, j;
 	u64 base = 0;
@@ -426,8 +426,6 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 			j = lmb_overlaps_region(&lmb.reserved, base, size);
 			if (j < 0) {
 				/* this area isn't reserved, take it */
-				if (lmb_add_region(&lmb.reserved, base, size) < 0)
-					return 0;
 				return base;
 			}
 			res_base = lmb.reserved.region[j].base;
@@ -436,7 +434,22 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 			base = lmb_align_down(res_base - size, align);
 		}
 	}
-	return 0;
+	return -1ULL;
+}
+
+u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
+{
+	u64 base;
+
+	base = __lmb_find_base(size, align, max_addr);
+
+	if (base == -1ULL)
+		return 0;
+
+	if (lmb_add_region(&lmb.reserved, base, size) < 0)
+		return 0;
+
+	return base;
 }
 
 /* You must call lmb_analyze() before this. */
-- 
1.6.4.2

--

From: Benjamin Herrenschmidt
Date: Monday, April 12, 2010 - 8:58 pm

Defininf some kind of LMB_ERROR would be nicer.

Cheers,


--

From: Yinghai
Date: Monday, April 12, 2010 - 9:31 pm

ok, also __lmb_alloc_base could return 0 when fail to get one.

replace that 0 with LMB_ERROR aka -1ULL?

Yinghai
--

Previous thread: [PATCH tip/core/urgent] rcu: updates for RCU lockdep by Paul E. McKenney on Thursday, April 8, 2010 - 10:47 pm. (26 messages)

Next thread: [PATCH 15/39] lmb: Add lmb_find_area_node() by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (3 messages)