]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
of: reserved_mem: rearrange code a bit
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 25 Mar 2026 09:00:21 +0000 (10:00 +0100)
committerRob Herring (Arm) <robh@kernel.org>
Thu, 26 Mar 2026 19:12:02 +0000 (14:12 -0500)
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>
drivers/of/of_reserved_mem.c

index 5dd585bcf8a824e90d5cd7d430f984d8ae5e50cd..f9b6d3ebcc203d3af5b0dcf0264d2fc286788401 100644 (file)
@@ -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