From: Kenny Cheng <chao.shun.cheng.tw@gmail.com>
To: robh@kernel.org, saravanak@kernel.org, kees@kernel.org
Cc: tony.luck@intel.com, gpiccoli@igalia.com, andersson@kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
c.s.cheng@realtek.com, Kenny Cheng <chao.shun.cheng.tw@gmail.com>
Subject: [PATCH] of: fix incorrect device creation for reserved memory nodes
Date: Sun, 22 Feb 2026 22:45:07 +0800 [thread overview]
Message-ID: <20260222144507.1736070-1-chao.shun.cheng.tw@gmail.com> (raw)
The current global search for nodes in reserved_mem_matches can find
nodes outside "/reserved-memory". These nodes might not have actual
memory reserved (via memblock), leading to drivers (e.g., ramoops)
accessing unreserved memory and causing memory corruption.
Prioritize scanning children of "/reserved-memory" to ensure the device
is backed by reserved memory. A fallback is kept for compatibility.
Proper reference counting is also added.
Signed-off-by: Kenny Cheng <chao.shun.cheng.tw@gmail.com>
---
drivers/of/platform.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ba591fbceb56..785ffef48c08 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -563,8 +563,17 @@ static int __init of_platform_default_populate_init(void)
* platform_devices for every node in /reserved-memory with a
* "compatible",
*/
- for_each_matching_node(node, reserved_mem_matches)
- of_platform_device_create(node, NULL, NULL);
+ reserved = of_find_node_by_path("/reserved-memory");
+ if (reserved) {
+ for_each_child_of_node(reserved, node) {
+ if (of_match_node(reserved_mem_matches, node))
+ of_platform_device_create(node, NULL, NULL);
+ }
+ of_node_put(reserved);
+ } else {
+ for_each_matching_node(node, reserved_mem_matches)
+ of_platform_device_create(node, NULL, NULL);
+ }
node = of_find_node_by_path("/firmware");
if (node) {
--
2.34.1
next reply other threads:[~2026-02-22 14:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 14:45 Kenny Cheng [this message]
2026-02-22 14:53 ` [PATCH v2] " Kenny Cheng
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=20260222144507.1736070-1-chao.shun.cheng.tw@gmail.com \
--to=chao.shun.cheng.tw@gmail.com \
--cc=andersson@kernel.org \
--cc=c.s.cheng@realtek.com \
--cc=devicetree@vger.kernel.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@kernel.org \
--cc=tony.luck@intel.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
all inboxes | Powered by JetHome®