[PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()

Yuntao Wang posted 10 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
Posted by Yuntao Wang 2 months, 4 weeks ago
The len value is in bytes, while `dt_root_addr_cells + dt_root_size_cells`
is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

Fixes: f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Fixes: e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a1db3c9ac981..716ebe8c23d3 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -821,7 +821,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 	pr_debug("Looking for elfcorehdr property... ");
 
 	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+	if (!prop || len < dt_root_addr_size_bytes())
 		return;
 
 	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
-- 
2.51.0