From: Yuntao Wang <yuntao.wang@linux.dev>
To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Cc: Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Baoquan He <bhe@redhat.com>,
Zhen Lei <thunder.leizhen@huawei.com>,
Chen Zhou <chenzhou10@huawei.com>,
Yuntao Wang <yuntao.wang@linux.dev>
Subject: [PATCH] of: fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()
Date: Sun, 2 Nov 2025 22:14:16 +0800 [thread overview]
Message-ID: <20251102141416.160192-1-yuntao.wang@linux.dev> (raw)
The len value is in bytes, while `dt_root_addr_cells + dt_root_size_cells`
is in cells (4 bytes per cell).
The modulo calculation between them is incorrect, the units must be
converted first.
Fixes: fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux,usable-memory-range"")
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
drivers/of/fdt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0edd639898a6..21ddc28a1257 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -852,6 +852,7 @@ void __init early_init_dt_check_for_usable_mem_range(void)
const __be32 *prop, *endp;
int len, i;
unsigned long node = chosen_node_offset;
+ int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
if ((long)node < 0)
return;
@@ -859,7 +860,7 @@ void __init early_init_dt_check_for_usable_mem_range(void)
pr_debug("Looking for usable-memory-range property... ");
prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
- if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells)))
+ if (!prop || len % t_len)
return;
endp = prop + (len / sizeof(__be32));
--
2.51.0
reply other threads:[~2025-11-02 14:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251102141416.160192-1-yuntao.wang@linux.dev \
--to=yuntao.wang@linux.dev \
--cc=bhe@redhat.com \
--cc=catalin.marinas@arm.com \
--cc=chenzhou10@huawei.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=thunder.leizhen@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox