From nobody Sat Feb 7 21:08:16 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64B702877FA for ; Sat, 15 Nov 2025 13:48:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214529; cv=none; b=S8IyIYtNRiUHD/59z+6yz6E4XvOfIOe68fV9OBGdMPGmlROX2LS7DkJGtK9P/ohhqGNGeXSK6gllkXTmbDXt9uTT4BCmz6qcvFJiBvgLpmIJV4eWIJyNEarmVHcSw4n4KatayWwpTrAUlsfwVQiL3H0eAMLxh8ZxTDTp9zTauBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214529; c=relaxed/simple; bh=jpYSKrwVd5Tft9gSSGXg8vERac336kKtjF7nhE6K2N8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uhiEO+HTRBtETmDIW2dZmQdULBqKoERU9Elx43rYUfJt4itdF6Gt64K4MN9WVDJHwvaEwSw/zhE7NO/jU+pprny5VSPx5PHGOD4attbVCgB49MsSvCDRt30LIP5CtdtsO6t41uO2UyIzHbzr8fefQcLFJW5M57PT4k1mRBhKPRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=o/xkQoBp; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="o/xkQoBp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mrfry8ZHlu6ltZbBTJZY2vFWEIq98NIOgqfig9bcFoE=; b=o/xkQoBpqX9aVp/LZ+zz/1GUxWAb70aMT2e/E6etJXNTtj6rT/oW39+q+9BNEf+2HoQ84C QkoK7JiDooH+y0mBP1YqOqAKgEuwdm7Y2P+E3zfLwymLynMsJcwIJ7Ot45PebHgI+8Sx32 UOtvTTMlR+Taj3NOZQCyy96ja+Tq+/A= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 1/8] of/fdt: Consolidate duplicate code into helper functions Date: Sat, 15 Nov 2025 21:47:46 +0800 Message-ID: <20251115134753.179931-2-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Currently, there are many pieces of nearly identical code scattered across different places. Consolidate the duplicate code into helper functions to improve maintainability and reduce the likelihood of errors. Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/of_fdt.h | 9 +++++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 0edd639898a6..0c18bdefbbee 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -625,6 +625,47 @@ const void *__init of_get_flat_dt_prop(unsigned long n= ode, const char *name, return fdt_getprop(initial_boot_params, node, name, size); } =20 +const __be32 *__init of_flat_dt_get_addr_size_prop(unsigned long node, + const char *name, + int *entries) +{ + const __be32 *prop; + int len, elen =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be= 32); + + prop =3D of_get_flat_dt_prop(node, name, &len); + if (!prop || len % elen) { + *entries =3D 0; + return NULL; + } + + *entries =3D len / elen; + return prop; +} + +bool __init of_flat_dt_get_addr_size(unsigned long node, const char *name, + u64 *addr, u64 *size) +{ + const __be32 *prop; + int entries; + + prop =3D of_flat_dt_get_addr_size_prop(node, name, &entries); + if (!prop || entries !=3D 1) + return false; + + of_flat_dt_read_addr_size(prop, 0, addr, size); + return true; +} + +void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, + u64 *addr, u64 *size) +{ + int entry_cells =3D dt_root_addr_cells + dt_root_size_cells; + prop +=3D entry_cells * entry_index; + + *addr =3D dt_mem_next_cell(dt_root_addr_cells, &prop); + *size =3D dt_mem_next_cell(dt_root_size_cells, &prop); +} + /** * of_fdt_is_compatible - Return true if given node from the given blob has * compat in its compatible list diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b8d6c0c20876..51dadbaa3d63 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -55,6 +55,15 @@ extern int of_get_flat_dt_subnode_by_name(unsigned long = node, const char *uname); extern const void *of_get_flat_dt_prop(unsigned long node, const char *nam= e, int *size); + +extern const __be32 *of_flat_dt_get_addr_size_prop(unsigned long node, + const char *name, + int *entries); +extern bool of_flat_dt_get_addr_size(unsigned long node, const char *name, + u64 *addr, u64 *size); +extern void of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, + u64 *addr, u64 *size); + extern int of_flat_dt_is_compatible(unsigned long node, const char *name); extern unsigned long of_get_flat_dt_root(void); extern uint32_t of_get_flat_dt_phandle(unsigned long node); --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A57122F6590 for ; Sat, 15 Nov 2025 13:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214537; cv=none; b=r/GciHTn7KaE35Uy7HRelkCvZurUnibOSTk5IorwKwOEd1ZDBXPwKYwA/rqP8e+bfXEQvKG+E2LXM/4HRv+A0m0RaG6Kt+PCmLZze0RE201p5y02RVf5sYsC3AIB0gUHKaO5kT9feS/O0bUWITUlF/e5ZB3O61siZ5VPhKe7CZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214537; c=relaxed/simple; bh=zsBvt9O2EDJa80tzC1ejES3SBfy8w+OS/3vuEC3oBHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZtfF+FGZUdcdJz7xXgKhG9FTnDBACCxtiZh1ERHZTLrgUHlz7OctxhjYTBTLqxepnZwMxByV3MQvVHET8RV8Z0MNr01cNAjx+ax2gT+7RmlofbxK1JeKOtgB9Je9k0UEb/Mspw5U8xMTBpItkctRIRjRv66eiF1qqAsWTnswfzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZNvpvnih; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZNvpvnih" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oH0tQ+eSb0QZhrUtBfRlSZkaLI+9L0kcGFd01oyVOes=; b=ZNvpvnihFwnbftEkXMaa0UfJ35yCyZbMlt+giGM2fVMl0UCHIKcNIbVue+lqRKpP/GYRLQ 7Nn+ETyMw8KaY7cR/ukQkONZBy6nsAVSZ6ahDxsgRTqU6/YVYJJ58/FdRxoO6EbdE9C5y1 X//jRGD6QjM8W34DFgph1dXAsaMvoUk= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 2/8] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Date: Sat, 15 Nov 2025 21:47:47 +0800 Message-ID: <20251115134753.179931-3-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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. Use a helper function to simplify the code and address this issue. Fixes: f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core he= aders property") Fixes: e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file") Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 0c18bdefbbee..b45f60dccd7c 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -853,21 +853,15 @@ static void __init early_init_dt_check_for_initrd(uns= igned long node) */ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) { - const __be32 *prop; - int len; - if (!IS_ENABLED(CONFIG_CRASH_DUMP)) return; =20 pr_debug("Looking for elfcorehdr property... "); =20 - prop =3D of_get_flat_dt_prop(node, "linux,elfcorehdr", &len); - if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells))) + if (!of_flat_dt_get_addr_size(node, "linux,elfcorehdr", + &elfcorehdr_addr, &elfcorehdr_size)) return; =20 - elfcorehdr_addr =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - elfcorehdr_size =3D dt_mem_next_cell(dt_root_size_cells, &prop); - pr_debug("elfcorehdr_start=3D0x%llx elfcorehdr_size=3D0x%llx\n", elfcorehdr_addr, elfcorehdr_size); } --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A7D82D739D for ; Sat, 15 Nov 2025 13:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214549; cv=none; b=qI03bGWLWlIoeoLhHGGTKvbCXk7SFIrB1kWuTUl+CLRslId0MZqBFjvXOJW2uo0pLQ1NFy1U7PcQ5Wajyp6vUrE5uMb9WsuNE9zkC8YeTYdONAPgjph3vyycbRI9DOZqTKCnNaubqQN+kq+KU5AEou9k9e6KvcrhjeFBwU42RBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214549; c=relaxed/simple; bh=ZZ/upw8nKT7v3jsEgzyAA289KSD3Fq5t653Jcf0SpvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H7IEIZ5ufsNZFEiwNdwuPPBVwJ6g+DGxrkrbcLEBaf0kQoUwozEQMUbQLZbOZZCz7akHATQBs99Ci4PVfMxIzjO3NsPHIZHEa0G03gbkLHCsIMoLtsxbZOihkACjc/HAinBIwONl1ZDiZqVf3ZW+DE8WnALmI2oALm0EH1zaCEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jGf/YTvc; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jGf/YTvc" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MY3v9cZNblUfD57tnTGju+AQf3Z40adow3kyHkwe/ps=; b=jGf/YTvccMn+mePMIqYv83allCJeKFRkEl95R/ptEoo346OizqpUg/IYbFQ4ykZr15UqCQ ZgcqPNY7AlaexiblLDEJc/ZUFrQJuC40h0pXaMuvbcq0wTL78nrIeNPGNIIEuBeLUQ1Z+k zF4v/CEHn/NU9jlbu9cXMa5yu0+5oME= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 3/8] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Date: Sat, 15 Nov 2025 21:47:48 +0800 Message-ID: <20251115134753.179931-4-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The len value is in bytes, while `dt_root_addr_cells + dt_root_size_cells` is in cells (4 bytes per cell). Modulo calculation between them is incorrect, the units must be converted first. Use helper functions to simplify the code and fix this issue. Fixes: fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux= ,usable-memory-range"") Fixes: 2af2b50acf9b9c38 ("of: fdt: Add generic support for handling usable = memory range property") Fixes: 8f579b1c4e347b23 ("arm64: limit memory regions based on DT property,= usable-memory-range") Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index b45f60dccd7c..ea37ba694bcd 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -884,8 +884,9 @@ static unsigned long chosen_node_offset =3D -FDT_ERR_NO= TFOUND; void __init early_init_dt_check_for_usable_mem_range(void) { struct memblock_region rgn[MAX_USABLE_RANGES] =3D {0}; - const __be32 *prop, *endp; + const __be32 *prop; int len, i; + u64 base, size; unsigned long node =3D chosen_node_offset; =20 if ((long)node < 0) @@ -893,14 +894,17 @@ void __init early_init_dt_check_for_usable_mem_range(= void) =20 pr_debug("Looking for usable-memory-range property... "); =20 - prop =3D of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); - if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells))) + prop =3D of_flat_dt_get_addr_size_prop(node, "linux,usable-memory-range", + &len); + if (!prop) return; =20 - endp =3D prop + (len / sizeof(__be32)); - for (i =3D 0; i < MAX_USABLE_RANGES && prop < endp; i++) { - rgn[i].base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - rgn[i].size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + len =3D min(len, MAX_USABLE_RANGES); + + for (i =3D 0; i < len; i++) { + of_flat_dt_read_addr_size(prop, i, &base, &size); + rgn[i].base =3D base; + rgn[i].size =3D size; =20 pr_debug("cap_mem_regions[%d]: base=3D%pa, size=3D%pa\n", i, &rgn[i].base, &rgn[i].size); --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24BB42F60CA for ; Sat, 15 Nov 2025 13:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214556; cv=none; b=hbzDh7mSnzZHcp2Dz7WXcqxecqG5jejVWZfODIU2iUkAUuyerW5twV6Nnhdr7k+JtAx+VfOdhEqbTlabCI87teeoWzWXIiatlC7scurKXCaolJrsJwIN1Ysaz+w/0bkDRryCeKCmO6qRFBX9Z/7ZPpCTwyKTkkVeZm6WoLm9xmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214556; c=relaxed/simple; bh=5in2a1+BQQ4kLHywx8wo7VUF9UeVxlyRUQJjc5LMDhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kdNMZiSuHpJHy11B+7Mx/ZgqwEuV/VlxbRyjALy2DcKeQZ5C1c5G4T1Ivxm4BpNm/0sK/HMNJ/uxZTJvHyBV49iz96UHDdAqU6LZAhDf+Vz0KlkX5PHwawKUrWmxk+mUizCEE2JhHjB9Lw4aZq2ZEbPG4FirsOV8kP2hWPihQDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=OqTAVQGt; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OqTAVQGt" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TqUrIKbmF5iQpt0Si3WZ6WoYb7H/IbcxUksZIbS12do=; b=OqTAVQGtYCdJqslk5woPrTyFggkVwtU4FWw6X4Mm3kiPmNPDxCGekzc7pfObWTsvWKxD19 b7OONUjg6WL/2W8Qd96xrhN5twtGIKHo3uv4gk0gFvfGBFIsOwWEPFxB4U3PHOlyGzzDLy drIpq79Z2lP902S/w5Apg77Vr2FvHXc= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 4/8] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Date: Sat, 15 Nov 2025 21:47:49 +0800 Message-ID: <20251115134753.179931-5-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" When reading the fdt_size value, the argument passed to dt_mem_next_cell() is dt_root_addr_cells, but it should be dt_root_size_cells. The same issue occurs when reading the scratch_size value. Use a helper function to simplify the code and fix these issues. Fixes: 274cdcb1c004 ("arm64: add KHO support") Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ea37ba694bcd..fdaee4906836 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -922,26 +922,18 @@ static void __init early_init_dt_check_kho(void) { unsigned long node =3D chosen_node_offset; u64 fdt_start, fdt_size, scratch_start, scratch_size; - const __be32 *p; - int l; =20 if (!IS_ENABLED(CONFIG_KEXEC_HANDOVER) || (long)node < 0) return; =20 - p =3D of_get_flat_dt_prop(node, "linux,kho-fdt", &l); - if (l !=3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)) + if (!of_flat_dt_get_addr_size(node, "linux,kho-fdt", + &fdt_start, &fdt_size)) return; =20 - fdt_start =3D dt_mem_next_cell(dt_root_addr_cells, &p); - fdt_size =3D dt_mem_next_cell(dt_root_addr_cells, &p); - - p =3D of_get_flat_dt_prop(node, "linux,kho-scratch", &l); - if (l !=3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)) + if (!of_flat_dt_get_addr_size(node, "linux,kho-scratch", + &scratch_start, &scratch_size)) return; =20 - scratch_start =3D dt_mem_next_cell(dt_root_addr_cells, &p); - scratch_size =3D dt_mem_next_cell(dt_root_addr_cells, &p); - kho_populate(fdt_start, fdt_size, scratch_start, scratch_size); } =20 --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4CB22877FA for ; Sat, 15 Nov 2025 13:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214573; cv=none; b=STFxxeCYcvNUa9ya2mCib/Pv1QEcbUb5qxHSjyodGl/oRa9Ht+9bJ1i1LGUpXXQzNYt7YKyZXm0h/BvufcDNR47x7GVFbYkXdwcN2ltyI7sSlIJ42sYDg7H6pXsdvD2JSPEjpVAUu20sUuTVMo3K1uIgz648mRzW78y6rSPE8bY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214573; c=relaxed/simple; bh=fmpEB35pIYZLj0gJCg7yla2LFVzXeaAL5ZdlyABTiC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r6jPq5XiG4G5Hiqt8LvUtXnr4HxxCqvcqFlpv2UaSUVWqLmjMWgS2eOOD84OgOeAKgPYvEzvfmNFxeHWi2NIxS3iV8ClZL2Qyl8eI7hdzk8qVA2HaolYPfQ5ewME6WVeUK5tEWL8Rl2505GA+6Sad08fkkEhxqEzHgvCSJIMbNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Lt3M7JYb; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Lt3M7JYb" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GnCwOF+dI773dn/Glk11DJ97ct85y2yDFhHBMya8yK0=; b=Lt3M7JYbY+KOk1WCou+FAAgZEsu4P1TA3aNkNvI6owDvkZ/aWYWzIza1k9yUVWnfzErRWi qCJUMYDdb/GdiyLAOtcs3DOJ1hih0+CqKiTf42JFLj6YldLb25wq4eoL3Zd3Hjy4hQfVVI wQYfN59H/iYWGOW9ICvCuAVBqtKyA8U= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 5/8] of/fdt: Simplify the logic of early_init_dt_scan_memory() Date: Sat, 15 Nov 2025 21:47:50 +0800 Message-ID: <20251115134753.179931-6-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use the existing helper functions to simplify the logic of early_init_dt_scan_memory() Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index fdaee4906836..d378d4b4109f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1033,8 +1033,8 @@ int __init early_init_dt_scan_memory(void) =20 fdt_for_each_subnode(node, fdt, 0) { const char *type =3D of_get_flat_dt_prop(node, "device_type", NULL); - const __be32 *reg, *endp; - int l; + const __be32 *reg; + int i, l; bool hotpluggable; =20 /* We are scanning "memory" nodes only */ @@ -1044,23 +1044,21 @@ int __init early_init_dt_scan_memory(void) if (!of_fdt_device_is_available(fdt, node)) continue; =20 - reg =3D of_get_flat_dt_prop(node, "linux,usable-memory", &l); + reg =3D of_flat_dt_get_addr_size_prop(node, "linux,usable-memory", &l); if (reg =3D=3D NULL) - reg =3D of_get_flat_dt_prop(node, "reg", &l); + reg =3D of_flat_dt_get_addr_size_prop(node, "reg", &l); if (reg =3D=3D NULL) continue; =20 - endp =3D reg + (l / sizeof(__be32)); hotpluggable =3D of_get_flat_dt_prop(node, "hotpluggable", NULL); =20 - pr_debug("memory scan node %s, reg size %d,\n", + pr_debug("memory scan node %s, reg {addr,size} entries %d,\n", fdt_get_name(fdt, node, NULL), l); =20 - while ((endp - reg) >=3D (dt_root_addr_cells + dt_root_size_cells)) { + for (i =3D 0; i < l; i++) { u64 base, size; =20 - base =3D dt_mem_next_cell(dt_root_addr_cells, ®); - size =3D dt_mem_next_cell(dt_root_size_cells, ®); + of_flat_dt_read_addr_size(reg, i, &base, &size); =20 if (size =3D=3D 0) continue; --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C125C2FB617 for ; Sat, 15 Nov 2025 13:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214581; cv=none; b=mag/I/zE0m9gCaIxl7zDQ5Gxl3KvHSdlrmsQuq2wk7qeR3gSH48JT5JnwDPn7An0g6/i7H1jrZGpDKpCPzW77IBugueTPXaLrppvOAwFqIW/jTm/m3EG4zYhGXr6ZG98QvKPnhI87V/TKpzhB/7n9gDEfTkf8zB7ovdc5HYGzTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214581; c=relaxed/simple; bh=2/gVDE54Ehb2rf84zXfmPE7yjVeewxAOW2mPPmmU+cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3astbywAmxOStAiuKzJChMqR0lR2dv0A3yf9WAY9kzuD2NAZf9btH/RNzqaz1hLRlyN8XxTNNfrsDz5s4uPREdoSFxZ5av2tcVRCVVBYrpNZZ0jfbgHAlkMY8uFC8I+6XEAsuMY1yfzZ9lO5fGpA61Yz/M20JzrFjRv8PgE5Dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PsuXtbkI; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PsuXtbkI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K4rABBY+wyZvCt1Mj6ISq9EmRtgABT8u7vKdxDl2W9c=; b=PsuXtbkIK6V2o6EZaq3WYfcEE+7z9DaECsrCCmWvCLF00OY+HUrL/1Yyosrpvkcc2nX2pR Y6wZOYeMs5V40wUbF9mtbPM7hx1sAKSFQwAOUcGBJG7UgsOnf7e40AICRfi30uSz5otdOO +RYZoRiRQ2D/O48CHEYLZbfDMyAw8FE= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 6/8] of/reserved_mem: Simplify the logic of __reserved_mem_reserve_reg() Date: Sat, 15 Nov 2025 21:47:51 +0800 Message-ID: <20251115134753.179931-7-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use the existing helper functions to simplify the logic of __reserved_mem_reserve_reg() Signed-off-by: Yuntao Wang --- drivers/of/of_reserved_mem.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 2e9ea751ed2d..2f1e4450785e 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -154,27 +154,24 @@ static int __init early_init_dt_reserve_memory(phys_a= ddr_t base, static int __init __reserved_mem_reserve_reg(unsigned long node, const char *uname) { - int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t base, size; - int len; + int i, len; const __be32 *prop; bool nomap; =20 - prop =3D of_get_flat_dt_prop(node, "reg", &len); + prop =3D of_flat_dt_get_addr_size_prop(node, "reg", &len); if (!prop) return -ENOENT; =20 - if (len && len % t_len !=3D 0) { - pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", - uname); - return -EINVAL; - } - nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; =20 - while (len >=3D t_len) { - base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + for (i =3D 0; i < len; i++) { + u64 b, s; + + of_flat_dt_read_addr_size(prop, i, &b, &s); + + base =3D b; + size =3D s; =20 if (size && early_init_dt_reserve_memory(base, size, nomap) =3D=3D 0) { /* Architecture specific contiguous memory fixup. */ @@ -187,8 +184,6 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, pr_err("Reserved memory: failed to reserve memory for node '%s': base %= pa, size %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); } - - len -=3D t_len; } return 0; } --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D84242FB966; Sat, 15 Nov 2025 13:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214590; cv=none; b=iDIGtjb7zVhghaK1n9jhXulOlXPk4GHKUNOLDvf08K8F/gDrrHOblnTFOtVbZZvUG2DdQAFPwamnUiF7VjTqZomn+WLIchmC9WvxKWBvHTG14qws/tEQM32h7DbzWPqMzRtqCCNYlrM5KFkf3CHoXs2U5xB/n/gvsiCB7AP01Lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214590; c=relaxed/simple; bh=vLfXegOczrFOX7ZwcNE5UI+0u9nsnsz5c/rfTcX+Tqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E6vE1WJZgVCNdhftdYeyYdZS4Y1QNvWWCq/4JkTgr4jdeF2VPT7uvvDXJLih9NetvwJyarGtuH5EI3KD95SEJTQcIHeNpfXiA2dWSXkeeM3Slf2wlJu8o++Xp9DFsBWdBihygfm0lJPMZTGpLonEuWp/J8HDPWGvgIfVXxtIKYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jD2E1j+C; arc=none smtp.client-ip=91.218.175.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jD2E1j+C" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b61z+7Zwzsrpkor1DhAY2hNXwtM/8j+ZHIAdx/g/Rtg=; b=jD2E1j+C/wTwHKpn+rlz5hCuBvzOyvU1Z8RyTATDPvQFeqTzzoKbotgjYyHGB22hGw+uPf 8O8NZSSwnTUVtVDlKI339mtqT1k7qZj0PC8PDWJRBprjVurePACusgicLnMZToNxtpJfVI /uT4kdkjA7iRiCiF1QMjFoawMbDsTDY= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 7/8] of/reserved_mem: Simplify the logic of fdt_scan_reserved_mem_reg_nodes() Date: Sat, 15 Nov 2025 21:47:52 +0800 Message-ID: <20251115134753.179931-8-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use the existing helper functions to simplify the logic of fdt_scan_reserved_mem_reg_nodes() Signed-off-by: Yuntao Wang --- drivers/of/of_reserved_mem.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 2f1e4450785e..0ceb096c17e6 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -225,12 +225,9 @@ static void __init __rmem_check_for_overlap(void); */ void __init fdt_scan_reserved_mem_reg_nodes(void) { - int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); const void *fdt =3D initial_boot_params; phys_addr_t base, size; - const __be32 *prop; int node, child; - int len; =20 if (!fdt) return; @@ -251,29 +248,21 @@ void __init fdt_scan_reserved_mem_reg_nodes(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; + u64 b, s; =20 - prop =3D of_get_flat_dt_prop(child, "reg", &len); - if (!prop) - continue; if (!of_fdt_device_is_available(fdt, child)) continue; =20 - uname =3D fdt_get_name(fdt, child, NULL); - if (len && len % t_len !=3D 0) { - pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n= ", - uname); + if (!of_flat_dt_get_addr_size(child, "reg", &b, &s)) continue; - } - - if (len > t_len) - pr_warn("%s() ignores %d regions in node '%s'\n", - __func__, len / t_len - 1, uname); =20 - base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + base =3D b; + size =3D s; =20 - if (size) + if (size) { + uname =3D fdt_get_name(fdt, child, NULL); fdt_reserved_mem_save_node(child, uname, base, size); + } } =20 /* check for overlapping reserved regions */ --=20 2.51.0 From nobody Sat Feb 7 21:08:16 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FA662FB62A for ; Sat, 15 Nov 2025 13:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214599; cv=none; b=tV+iyXNyXsHLXUlTSU0n7P0efae3ac8ZuLY/AQbVZh7895rrFV97pL+9BOG5YpM1PaifUlKUqK9QGT7mvc/QEUBWIqvhQ+PqWLO3SiebzxCEW4sGyq7DzSvHUNNBYs6q5nHkHsI/KFD9ZvOWRol48pRH4lMbKWYMMcRADpr/fMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214599; c=relaxed/simple; bh=K/Q+XUVIKKsLqxQRg9fWMCwmkkmfKYaeE5QXe1gNLgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pa0FV1FgjW1k2mkNesU0pJzw4A793Y8iIXjiYbtWHGdtuZskthpMTq3b+7P9lW5H4JdPcPaMPRU+OZUTbf8YEIRjf+GolCdPsQvY2IgGq387cM1AWKpgp6rxmLlxrt4PLOU/9GmHJGEw1v/tqZYn36e1Eny6K7LkffbfgKEkDo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Z2urmUtA; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Z2urmUtA" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763214595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5q3dAmTTGvh2D1uCjxlq4hOfI5Qlfk0JDHPgJGUEfUI=; b=Z2urmUtAbikyTUIdKpQ9l7gWq64hHiJbagbrB452bWnGar9uOK5cvtbkSvlqO8FaNTrM/d BraN3N0iPjS10oIp/qVCN7JjzDf/0OZhwszr2Rkdqy2saXhCfP0I/M4whlYeSH4hU8CdLM 9t8k6D1yj5TsK3SoSKIdpQ7zMXvQuMM= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v3 8/8] of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size() Date: Sat, 15 Nov 2025 21:47:53 +0800 Message-ID: <20251115134753.179931-9-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use the existing helper functions to simplify the logic of __reserved_mem_alloc_size() Signed-off-by: Yuntao Wang --- drivers/of/of_reserved_mem.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 0ceb096c17e6..5619ec917858 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -385,10 +385,9 @@ static int __init __reserved_mem_alloc_in_range(phys_a= ddr_t size, */ static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname) { - int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t start =3D 0, end =3D 0; phys_addr_t base =3D 0, align =3D 0, size; - int len; + int i, len; const __be32 *prop; bool nomap; int ret; @@ -422,19 +421,15 @@ static int __init __reserved_mem_alloc_size(unsigned = long node, const char *unam && !nomap) align =3D max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); =20 - prop =3D of_get_flat_dt_prop(node, "alloc-ranges", &len); + prop =3D of_flat_dt_get_addr_size_prop(node, "alloc-ranges", &len); if (prop) { + for (i =3D 0; i < len; i++) { + u64 b, s; =20 - if (len % t_len !=3D 0) { - pr_err("invalid alloc-ranges property in '%s', skipping node.\n", - uname); - return -EINVAL; - } + of_flat_dt_read_addr_size(prop, i, &b, &s); =20 - while (len > 0) { - start =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - end =3D start + dt_mem_next_cell(dt_root_size_cells, - &prop); + start =3D b; + end =3D b + s; =20 base =3D 0; ret =3D __reserved_mem_alloc_in_range(size, align, @@ -445,9 +440,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam (unsigned long)(size / SZ_1M)); break; } - len -=3D t_len; } - } else { ret =3D early_init_dt_alloc_reserved_memory_arch(size, align, 0, 0, nomap, &base); --=20 2.51.0