From: Benjamin Herrenschmidt on
Since we allocate one more than needed, why not do a bit of sanity checking
here to ensure we don't walk past the end of the array ?

Signed-off-by: Benjamin Herrenschmidt <benh(a)kernel.crashing.org>
---
lib/lmb.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 27dbb9c..6765a3a 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -13,6 +13,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/bitops.h>
+#include <linux/poison.h>
#include <linux/lmb.h>

struct lmb lmb;
@@ -112,6 +113,10 @@ void __init lmb_init(void)
lmb.reserved.regions = lmb_reserved_init_regions;
lmb.reserved.max = INIT_LMB_REGIONS;

+ /* Write a marker in the unused last array entry */
+ lmb.memory.regions[INIT_LMB_REGIONS].base = (phys_addr_t)RED_INACTIVE;
+ lmb.reserved.regions[INIT_LMB_REGIONS].base = (phys_addr_t)RED_INACTIVE;
+
/* Create a dummy zero size LMB which will get coalesced away later.
* This simplifies the lmb_add() code below...
*/
@@ -131,6 +136,12 @@ void __init lmb_analyze(void)
{
int i;

+ /* Check marker in the unused last array entry */
+ WARN_ON(lmb_memory_init_regions[INIT_LMB_REGIONS].base
+ != (phys_addr_t)RED_INACTIVE);
+ WARN_ON(lmb_reserved_init_regions[INIT_LMB_REGIONS].base
+ != (phys_addr_t)RED_INACTIVE);
+
lmb.memory_size = 0;

for (i = 0; i < lmb.memory.cnt; i++)
--
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/