aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2015-11-18 05:46:38 -0500
committerRob Herring <robh@kernel.org>2015-11-30 18:56:44 -0500
commit9eb8cd2b0780bca0719e754e7bdcf5f368f001bd (patch)
tree9f5da3f090e540502f9b0f6c7ea7256a98e5f106
parent31ade3b83e1821da5fbb2f11b5b3d4ab2ec39db8 (diff)
of: Fix comparison of reserved memory regions
In order to check for overlapping reserved memory regions, we first need to sort the array of memory regions. This is implemented using sort(), and a custom comparison function __rmem_cmp(). Unfortunatley __rmem_cmp() doesn't work in all cases. Because the two base values are phys_addr_t, they may be u64 on some platforms, in which case subtracting one from the other and then (implicitly) casting to int does not give us the -ve/0/+ve value we need. This leads to incorrect reports about overlaps, eg: ibm,slw-image@1ffe600000 (0x0000001ffe600000--0x0000001ffe700000) overlaps with ibm,firmware-allocs-memory@1000000000 (0x0000001000000000--0x0000001000dc0200) Fix it by just doing the standard double if and return 0 logic. Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory regions") Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r--drivers/of/of_reserved_mem.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index be77e75c587d..1a3556a9e9ea 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -206,7 +206,13 @@ static int __init __rmem_cmp(const void *a, const void *b)
206{ 206{
207 const struct reserved_mem *ra = a, *rb = b; 207 const struct reserved_mem *ra = a, *rb = b;
208 208
209 return ra->base - rb->base; 209 if (ra->base < rb->base)
210 return -1;
211
212 if (ra->base > rb->base)
213 return 1;
214
215 return 0;
210} 216}
211 217
212static void __init __rmem_check_for_overlap(void) 218static void __init __rmem_check_for_overlap(void)