diff options
| author | Marek Szyprowski <m.szyprowski@samsung.com> | 2026-03-25 12:00:21 +0300 |
|---|---|---|
| committer | Rob Herring (Arm) <robh@kernel.org> | 2026-03-26 22:12:02 +0300 |
| commit | 427864f793eb69ae3f33aed0fcbe625809412366 (patch) | |
| tree | b154c24ec3a64d250987d06b4dac75a1c6e53e62 | |
| parent | 7fd3981202b9aef8862aa06ca0d75496c0f9681f (diff) | |
| download | linux-427864f793eb69ae3f33aed0fcbe625809412366.tar.xz | |
of: reserved_mem: rearrange code a bit
Move __rmem_check_for_overlap() and __rmem_cmp() functions before
fdt_scan_reserved_mem_reg_nodes() to avoid forward declaration and keep
related code close together.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://patch.msgid.link/20260325090023.3175348-6-m.szyprowski@samsung.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
| -rw-r--r-- | drivers/of/of_reserved_mem.c | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 5dd585bcf8a8..f9b6d3ebcc20 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -214,7 +214,55 @@ static int __init __reserved_mem_check_root(unsigned long node) return 0; } -static void __init __rmem_check_for_overlap(void); +static int __init __rmem_cmp(const void *a, const void *b) +{ + const struct reserved_mem *ra = a, *rb = b; + + if (ra->base < rb->base) + return -1; + + if (ra->base > rb->base) + return 1; + + /* + * Put the dynamic allocations (address == 0, size == 0) before static + * allocations at address 0x0 so that overlap detection works + * correctly. + */ + if (ra->size < rb->size) + return -1; + if (ra->size > rb->size) + return 1; + + return 0; +} + +static void __init __rmem_check_for_overlap(void) +{ + int i; + + if (reserved_mem_count < 2) + return; + + sort(reserved_mem, reserved_mem_count, sizeof(reserved_mem[0]), + __rmem_cmp, NULL); + for (i = 0; i < reserved_mem_count - 1; i++) { + struct reserved_mem *this, *next; + + this = &reserved_mem[i]; + next = &reserved_mem[i + 1]; + + if (this->base + this->size > next->base) { + phys_addr_t this_end, next_end; + + this_end = this->base + this->size; + next_end = next->base + next->size; + pr_err("OVERLAP DETECTED!\n%s (%pa--%pa) overlaps with %s (%pa--%pa)\n", + this->name, &this->base, &this_end, + next->name, &next->base, &next_end); + } + } +} /** * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined @@ -565,55 +613,6 @@ static int __init __reserved_mem_init_node(struct reserved_mem *rmem, return ret; } -static int __init __rmem_cmp(const void *a, const void *b) -{ - const struct reserved_mem *ra = a, *rb = b; - - if (ra->base < rb->base) - return -1; - - if (ra->base > rb->base) - return 1; - - /* - * Put the dynamic allocations (address == 0, size == 0) before static - * allocations at address 0x0 so that overlap detection works - * correctly. - */ - if (ra->size < rb->size) - return -1; - if (ra->size > rb->size) - return 1; - - return 0; -} - -static void __init __rmem_check_for_overlap(void) -{ - int i; - - if (reserved_mem_count < 2) - return; - - sort(reserved_mem, reserved_mem_count, sizeof(reserved_mem[0]), - __rmem_cmp, NULL); - for (i = 0; i < reserved_mem_count - 1; i++) { - struct reserved_mem *this, *next; - - this = &reserved_mem[i]; - next = &reserved_mem[i + 1]; - - if (this->base + this->size > next->base) { - phys_addr_t this_end, next_end; - - this_end = this->base + this->size; - next_end = next->base + next->size; - pr_err("OVERLAP DETECTED!\n%s (%pa--%pa) overlaps with %s (%pa--%pa)\n", - this->name, &this->base, &this_end, - next->name, &next->base, &next_end); - } - } -} /** * fdt_init_reserved_mem_node() - Initialize a reserved memory region |
