[PATCH v2 4/4] memblock: initialize the region merge end index
From: Tianyi Chen
Date: Tue Sep 22 2026 - 22:33:05 EST
GCC 13 reports that end_rgn may be used uninitialized when building the
memblock simulator with BUILD=32 and its default sanitizer flags.
Every insertion sets end_rgn, and the nr_new check prevents merging when
there were no insertions, so this is not an uninitialized read. Initialize
the index to zero to avoid the warning without disabling the diagnostic.
Reported-by: Mike Rapoport <rppt@xxxxxxxxxx>
Link: https://lore.kernel.org/r/179007180279.508753.4595268983388589280.b4-review@b4
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@xxxxxxxxx>
---
mm/memblock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index 22d14a637f24..aee1fe36130b 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -614,7 +614,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
bool insert = false;
phys_addr_t obase = base;
phys_addr_t end = base + memblock_cap_size(base, &size);
- int idx, nr_new, start_rgn = -1, end_rgn;
+ int idx, nr_new, start_rgn = -1, end_rgn = 0;
struct memblock_region *rgn;
if (!size)
--
2.55.0