summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Cheng <chao.shun.cheng.tw@gmail.com>2026-02-23 02:47:15 +0300
committerRob Herring (Arm) <robh@kernel.org>2026-02-28 02:49:31 +0300
commit28f060c4b0667a7fbed9818ef19b6974d53ad708 (patch)
tree7d9fe51afae2d47bd8be6f231952a0aecb241d7a
parentbe4b91d9aae51cfbc1d80f899c0f8aad081fc711 (diff)
downloadlinux-28f060c4b0667a7fbed9818ef19b6974d53ad708.tar.xz
of: fix incorrect device creation for reserved memory nodes
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. Restrict the scan to the "/reserved-memory" node to ensure created devices are correctly backed by reserved memory. This enforces specification compliance and avoids dangerous probing. Signed-off-by: Kenny Cheng <chao.shun.cheng.tw@gmail.com> Link: https://patch.msgid.link/20260222234715.1748302-1-chao.shun.cheng.tw@gmail.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
-rw-r--r--drivers/of/platform.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ba591fbceb56..2a7111e8354d 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -500,7 +500,7 @@ static const struct of_device_id reserved_mem_matches[] = {
static int __init of_platform_default_populate_init(void)
{
- struct device_node *node;
+ struct device_node *node, *reserved;
device_links_supplier_sync_state_pause();
@@ -563,8 +563,14 @@ 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);
+ }
node = of_find_node_by_path("/firmware");
if (node) {