From nobody Sat Feb 7 21:24:51 2026 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.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 ACB47346FAB for ; Thu, 13 Nov 2025 15:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049142; cv=none; b=V0mzMhiUwy282Cqt5dNRgA3y9TDaooaRZkfdC6kFGs3gU34+iXHhAT5YWuza28EXfQk/uXs5ydd7wL9Z3yencUFTce7s92E2J4Z7C0uSHOrqLJH2+LWosZqImTCegDLXR6zCObL3mym6QRdajQDi3bTRtQsIx0OO8iNWuANYckg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049142; c=relaxed/simple; bh=0NhSeTl/snE7z5Fdpm4OWzOjQK7ApfL9mhPE8pL+RqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ugd8iDzvfSXlvo/H8GAqJQOq5yhWTh2qX/Ey+fadzAnspYETmXV4SmEaEx6rpHLfk+60Us4/9BtnUiSIWaeFpeU2LbnGoMcvwNGXcV/N3wl1yga9mrd4ff+LJB8rRyeNmnvAcoqIryubnrQzFF4BS2mZN3QpIJOq1ugz3DEIhgI= 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=TOUbEjPg; arc=none smtp.client-ip=95.215.58.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="TOUbEjPg" 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=1763049138; 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=2FL1PcC0VA6JulAHPdLFNyV1ulA8PzIof8YPayCQbY4=; b=TOUbEjPgaprY6ccn37/B8m5bUQqZ8UYWTaxdKlUnLDvhn5Vwf5SmJnZJEpDnL0o/shAoGH svyYOYJxXZPCeoWAqgC1G948IMVTiA5zP3FgE+nJPZyxtu6AFGAKr9fLXUffU9IcCKeirg y+uDRtIkQnAcfWxGs9FChr887kVAEjU= 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 v2 1/7] of/fdt: Consolidate duplicate code into helper functions Date: Thu, 13 Nov 2025 23:50:58 +0800 Message-ID: <20251113155104.226617-2-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 5 +++++ 2 files changed, 46 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 0edd639898a6..5e0eabc1449f 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_fdt_get_addr_size_prop(unsigned long node, + const char *name, int *entr= ies) +{ + 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) { + *entries =3D 0; + return NULL; + } + + if (len % elen) { + *entries =3D -1; + return NULL; + } + + *entries =3D len / elen; + return prop; +} + +bool __init of_fdt_get_addr_size(unsigned long node, const char *name, + u64 *addr, u64 *size) +{ + 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) + return false; + + of_fdt_read_addr_size(prop, addr, size); + return true; +} + +void __init of_fdt_read_addr_size(const __be32 *prop, u64 *addr, u64 *size) +{ + *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..3a0805ff6c7b 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -55,6 +55,11 @@ 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_fdt_get_addr_size_prop(unsigned long node, + const char *name, int *entr= ies); +extern bool of_fdt_get_addr_size(unsigned long node, const char *name, + u64 *addr, u64 *size); +extern void of_fdt_read_addr_size(const __be32 *prop, 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:24:51 2026 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 64611346E66 for ; Thu, 13 Nov 2025 15:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049151; cv=none; b=mRSOrheY6PCMz0LTI50niVfyz23RHRqDrcurhZ4Tzr+feTeVzqg8SJo0PXxjeHxkkDUww3Wb+RidFm4MaezdEaoSAFzlejBkvNXBLlQSbnTfcTvJDsIoP7wHrFO5mlOOwkUWmv08/wUUaL3sFbMiySVXeP9oOLQASefP+ulFCJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049151; c=relaxed/simple; bh=5yoEAT3UKNpdNhJ3r2BvPW5KJ/MD7k++shVS+I3ry0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DB2I7sUoS8jURT9KiQJ4oAWVdxoBNC6Z6zdvgPWVyVk4Zlo1DLH4U1GIygrmvMeuGKOPNctTYhs4MSBFstwzok9mtECGDfzpCF3o7n5wA/UlgRJY1Ejry5tNDqJ5S3TPbZ45yDIisEpCKUIw3XqjORPkPfkK/pjuVxj9+PZ80Ao= 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=nCIKUM/4; arc=none smtp.client-ip=95.215.58.174 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="nCIKUM/4" 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=1763049147; 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=XXQZDJE0Tzw/iE/HpyiouujjdObxwq13z1KP0WfIR7c=; b=nCIKUM/4z5pMIoug3+ihnpTDCQOs81uJm+nNiAGFNFoZ3pig3T6hR/4E23IOcNv2WjAb/p JLASHq+YMe8EdTxZrfQ3imabOUXBu84JfdtlNrjRTENKWBsnqH+c9A9vRZzQXn0OZ7woQO 8g3cNXdd3+g7ooVkURaBT2npY5rJWYo= 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 v2 2/7] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Date: Thu, 13 Nov 2025 23:50:59 +0800 Message-ID: <20251113155104.226617-3-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 5e0eabc1449f..80b7236efdc6 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_fdt_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:24:51 2026 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 9481934572F for ; Thu, 13 Nov 2025 15:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049159; cv=none; b=Ig9u7JQueYUBQIda7zVF9yNCsiqzLDHNkfrBuUUhImDf9PGJGPAoNGb9gCcNtjkjYFxMge4BTdJHWok8WYug9XmTjmp+d2j8tVPzwcbOYDKWfdtOKIQOnlhbedEiF0liRaGXTixD4G8+O9g/uvJpU/sn8SnZlyGUWmOCZYIYq4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049159; c=relaxed/simple; bh=7tr+1d/3tzMsJWc39iUs0JefrX9nWMAO5RdM4bye1Ho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uvbF9R/qrsxsj9u5DQl5CCJf6eT7lgVcLF5UDOTGScDQHRVKwucajbhURq9PRyWIqIddLQKlF2LbIGK3wkWWxx3L3W/SAGZM1z8dtkYIVcg5zU80b/FtI0rqE0Zc+OHxRLGK3grCm6WkkKHDMZMskpeLDCD1wnRm4HSKGWN+IkA= 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=OcD67eL2; arc=none smtp.client-ip=95.215.58.189 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="OcD67eL2" 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=1763049155; 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=0aseI6OseIhLle9z0TIJUXBxDfgB+PP1F776zvPg86w=; b=OcD67eL2D/fAb4UMXMVkT6oVR3dO6NqfPBh9x9n2VWLudSuJ8LJtILV8E1mVu1deFE5hkB 0e+gUUGEzz6JfQd493Rj5TfsMU70llFU8um92qpiSNYmCnjN4VGZUY27EQGjpOeSoI4Fhl +73bhc3zZ0xb0X5MykYdR3uU+h4O6Gw= 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 v2 3/7] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Date: Thu, 13 Nov 2025 23:51:00 +0800 Message-ID: <20251113155104.226617-4-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 80b7236efdc6..d0caaab42aa7 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -884,7 +884,7 @@ 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; unsigned long node =3D chosen_node_offset; =20 @@ -893,14 +893,14 @@ 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_fdt_get_addr_size_prop(node, "linux,usable-memory-range", &le= n); + 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_fdt_read_addr_size(prop, &rgn[i].base, &rgn[i].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:24:51 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 4F23E354719 for ; Thu, 13 Nov 2025 15:52:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049168; cv=none; b=isvBbjLjmUTFWU1z2PXD1zDYguC/POvTTf55NnsBMQ0XY+kC/G3h18/8w6iztl8Y7n+DzQAQnMZgNxyk+B3+GpQOnLfOtZaUzRjwLwhH2icSlxeSIKSGWcl5pEiTmHVL63NJ/belD6WzUy6+WL+MXxMIcBv+rdIYvQIvlWsELgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049168; c=relaxed/simple; bh=5G5liWqxFwcJ7D8RGsG/gE2IicV/yIFdjGkZjr7uurQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b/LGO4S2elGdY3b+OjPorFsmr/GEBqXhXd48yGVwITchRhUdOQs2zWbxjFOgd2xUbf7/l20+aLhCII+eUpifN1CoZi9PpwwBw1dv2Ju78Au/d8OdM+GC8NyA9qXJTsS35XRKIRVSreN4gu01kCtbvNZqtdbdJbN1mIJ9fNGDfW4= 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=AbRu5Qpz; arc=none smtp.client-ip=95.215.58.187 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="AbRu5Qpz" 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=1763049164; 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=qItt33BqcN4ZI2ZReVqmwV+XG/u/w5Cwqt20oaz5aDg=; b=AbRu5QpzyVlPqtd8LU36S3Ru7fu4y4YOTEd9tpa7DbdjEukuf3F0exSzOzVnt4IE8TZOlg kpDZR4r3/TEXAlUWfpa3eS/82ViLx7kPs9PLYupB7RRHUvaN8yc58p8jA4G3TLeDmx7KS8 GTpYVka0FageKAGsVDEZnifspLLmOeY= 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 v2 4/7] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Date: Thu, 13 Nov 2025 23:51:01 +0800 Message-ID: <20251113155104.226617-5-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d0caaab42aa7..4c45a97d6652 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -918,26 +918,16 @@ 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_fdt_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_fdt_get_addr_size(node, "linux,kho-scratch", &scratch_start, &scr= atch_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:24:51 2026 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.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 E359F355022 for ; Thu, 13 Nov 2025 15:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049176; cv=none; b=CPfjGEs6AUKmj1CRl+MoSeIChZ0zWt3FfmUDcy9YQ+5MWXISPKMOsq6PWBY4IiIeVJuCxY643/Si4HjGR3NJfRxeSU2Pd00vv+Z+n/741KXF0fyR7btzhDtwqmSbg46ASOi3T7+Xku9NYFTtoAwEMdkfZokSHGV7lReryWZeLaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049176; c=relaxed/simple; bh=fXl+mXM/AgH4+gWKzqK1XQgPchHG6fLIdy11kWGVzq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F25tcohO+m9RjIfki598qIMplMNPKFUUG6CVa28dQd9MQaUgL2PVmtws1TaFtVZm48xcyisTdGfJTlaBQkfZoCxtUu+ndDbanAB7gC/Ipr6gBcKycU+5WBz+XjKOTy34W+l9FWG57Yg/kkCINE6+IEFX5/URo3rOlpu8ENpe8pU= 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=U7z4KQXq; arc=none smtp.client-ip=95.215.58.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="U7z4KQXq" 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=1763049173; 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=J9UNF6c7GepepH7wr+REukLkpUqCyIFHcXGXKzxLcbU=; b=U7z4KQXqc+YTUJVB7A/GcWVkKVsCw933NyXN+fw7bGYJIyvMts5CS5KtYXgsDci7ks2c7J BqfrkfTGc04oNJotEh9zzUT7ZWE3B9zgcFzd5JfSquhW6UZpopo2dTBATR+VW95vQGACLw 7A9LN0zKX7fFzlKjUrdaCoebdukPCQo= 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 v2 5/7] of/fdt: Simplify the logic of early_init_dt_scan_memory() Date: Thu, 13 Nov 2025 23:51:02 +0800 Message-ID: <20251113155104.226617-6-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4c45a97d6652..b6b059960fc2 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1027,7 +1027,7 @@ 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; + const __be32 *reg; int l; bool hotpluggable; =20 @@ -1038,23 +1038,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_fdt_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_fdt_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)) { + while (l-- > 0) { 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_fdt_read_addr_size(reg, &base, &size); =20 if (size =3D=3D 0) continue; --=20 2.51.0 From nobody Sat Feb 7 21:24:51 2026 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 42866355054 for ; Thu, 13 Nov 2025 15:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049184; cv=none; b=crgYcftkLJYSVSf4IVFZdiMRlaZQ2kfBx5Fr9PtILRYuzIB7I3N6lNgv+raMd3CPrIa+6fDp9qy63hFnhW8Q4qYRvophrclX8S4tu7XydMPedfOQxEdptr8ctp7n+tfZT7qpwsNAjoB0j8hnysof8PwGdBvXv2ePc0jjWZhogBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049184; c=relaxed/simple; bh=tprO6N0gVwnG1G8yHuIS5dI+Sf8VvxGP72vdtdY0NV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WfXMAirL/3vqlwp+Z5+YVE3ESTKJTnA12OYItXefwXZwWBCRrHuuEBRBuJecgiR54CqQv66Cc8r0j1N+UnOkQm2IzETYnsKB2soP2gQrZ1MwGcnfps8CQMpQWxWJ2kKzlfhMqmjhutFjqhnqI+YOZYngY0kwk7StAmdM60uZkno= 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=JwjvrLB8; arc=none smtp.client-ip=95.215.58.174 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="JwjvrLB8" 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=1763049181; 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=SdhoUiNDDhmkZBcf7Fv2t++iSbCGwWq7uyL4ru5W8uw=; b=JwjvrLB85U9mDl3W5zTWCoQjGKz4VB6mH1x+vEyjfprXPhN8PSNUYyzt/KDnsfbHgxe05q voihqUjWWU3cx2RzJsxdlLnlzKwPRzrrqoceOe80sxX4FF/5uvTDahgys5djzy3Os/2Il3 3RxDPG0uMlTB+1JwzoD0Q/BeuVvlnek= 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 v2 6/7] of/reserved_mem: Simplify the logic of __reserved_mem_reserve_reg() Date: Thu, 13 Nov 2025 23:51:03 +0800 Message-ID: <20251113155104.226617-7-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 2e9ea751ed2d..b8527f3e335e 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -154,17 +154,16 @@ 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; const __be32 *prop; bool nomap; =20 - prop =3D of_get_flat_dt_prop(node, "reg", &len); - if (!prop) + prop =3D of_fdt_get_addr_size_prop(node, "reg", &len); + if (!len) return -ENOENT; =20 - if (len && len % t_len !=3D 0) { + if (len < 0) { pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", uname); return -EINVAL; @@ -172,9 +171,8 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, =20 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); + while (len-- > 0) { + of_fdt_read_addr_size(prop, &base, &size); =20 if (size && early_init_dt_reserve_memory(base, size, nomap) =3D=3D 0) { /* Architecture specific contiguous memory fixup. */ @@ -187,8 +185,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:24:51 2026 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 302C73559EC for ; Thu, 13 Nov 2025 15:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049193; cv=none; b=kgFEk7rxl3FqjquMpQjOQOukczI9E1hTIWbQQnW0VUmJAApup9eWwoPiudzDoBqex49556XOUhVEQDSopGx49XZc0qG8K9c8KTjcSWngS0sCUWXqrO3cl4YTpu98cCwr0Xsn7Nrzfen/yozCsjfHSgr7DTuY8ovpFiZrB1cHoeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049193; c=relaxed/simple; bh=h0I4DiDc6GNRbFsL/Gt4N1M9ywNyj1x0U7W30l0Ik28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMR2jUbR7faw1tsq2lRtYahoWahX8uY1N6207cm0jrsYLb4JmM8ddQ/oKMbGnGACtRyrYfQSJZqnoamVh7ixqfFGqempV5XrOL4tSy9iWSjG99cTHIMOtS+tmRVbOTitWWU9a9DQiIIrZZ0Wshat94655v9DM8b/iKG6rp7U8N0= 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=JlCWmwV6; arc=none smtp.client-ip=95.215.58.181 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="JlCWmwV6" 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=1763049190; 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=pShwBBnHbUhZjtMedCnDarjH+85reRacRSdZz081jWs=; b=JlCWmwV6LNHVwM35IYShejrxG9OpkFm7eSFGRK/PQRfeyKvrIL6nq7ONQTALg1D8NnmXmA eKJK0iTYF8y4TxH73SIIb71XGFhJaGDkouvQndOVfQrq+0nRvbHPaNJdHAQ+kJ1IR2fwSz pfbQC9yAifND6ZNZ4qxy3v+KqB++rSM= 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 v2 7/7] of/reserved_mem: Simplify the logic of fdt_scan_reserved_mem_reg_nodes() Date: Thu, 13 Nov 2025 23:51:04 +0800 Message-ID: <20251113155104.226617-8-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-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 | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index b8527f3e335e..96771ab073c0 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -226,12 +226,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; @@ -253,28 +250,16 @@ void __init fdt_scan_reserved_mem_reg_nodes(void) fdt_for_each_subnode(child, fdt, node) { const char *uname; =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_fdt_get_addr_size(child, "reg", &base, &size)) 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); - - 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