Skip to content

Commit 4cea282

Browse files
stephan-ghrobherring
authored andcommitted
of: reserved_mem: Use stable allocation order
sort() in Linux is based on heapsort which is not a stable sort algorithm - equal elements are being reordered. For reserved memory in the device tree this happens mainly for dynamic allocations: They do not have an address to sort with, so they are reordered somewhat randomly when adding/removing other unrelated reserved memory nodes. Functionally this is not a big problem, but it's confusing during development when all the addresses change after adding unrelated reserved memory nodes. Make the order stable by sorting dynamic allocations according to the node order in the device tree. Static allocations are not affected by this because they are still sorted by their (fixed) address. Signed-off-by: Stephan Gerhold <stephan@gerhold.net> Link: https://lore.kernel.org/r/20230510-dt-resv-bottom-up-v2-2-aeb2afc8ac25@gerhold.net Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 83ba736 commit 4cea282

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/of/of_reserved_mem.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ static int __init __rmem_cmp(const void *a, const void *b)
268268
if (ra->size > rb->size)
269269
return 1;
270270

271+
if (ra->fdt_node < rb->fdt_node)
272+
return -1;
273+
if (ra->fdt_node > rb->fdt_node)
274+
return 1;
275+
271276
return 0;
272277
}
273278

0 commit comments

Comments
 (0)