Skip to content

Commit

Permalink
of: Fix comparison of reserved memory regions
Browse files Browse the repository at this point in the history
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: ae1add2 ("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>
  • Loading branch information
Michael Ellerman authored and Rob Herring committed Nov 30, 2015
1 parent 31ade3b commit 9eb8cd2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/of/of_reserved_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ static int __init __rmem_cmp(const void *a, const void *b)
{
const struct reserved_mem *ra = a, *rb = b;

return ra->base - rb->base;
if (ra->base < rb->base)
return -1;

if (ra->base > rb->base)
return 1;

return 0;
}

static void __init __rmem_check_for_overlap(void)
Expand Down

0 comments on commit 9eb8cd2

Please sign in to comment.