of: reserved_mem: Use stable allocation order
authorStephan Gerhold <stephan@gerhold.net>
Wed, 14 Jun 2023 19:20:43 +0000 (21:20 +0200)
committerRob Herring <robh@kernel.org>
Tue, 20 Jun 2023 15:34:58 +0000 (09:34 -0600)
commit4cea2821882b06cd2c9c896d501f58746c16a90b
tree8098cee3f6157228bed7cde4e2d3a7dec4dda90d
parent83ba7361e168cd7b24aa95d2aefb4e31e3cc6cd0
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>
drivers/of/of_reserved_mem.c