From nobody Fri Apr 17 07:58:34 2026 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFCFE335BA for ; Sun, 22 Feb 2026 14:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771772035; cv=none; b=YQC2hGIB0IyMxDA7yeX1hlHLMtO6qibg5YDm3W856HxBXsUCj7l4cxag0NvMdrpWi8e3JEB3FJC9CF4TvrkebA5HuP779oROt0jjmQthz0v6zIIDf3nK9kVeWFjlHuR+CCB0rain/KfLKiRlTqH8vhVC0pmQ4tzFQq8iuv6NQCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771772035; c=relaxed/simple; bh=Z+/k4DynzAY0cJv7pPSLfFgb15c1OOZbG3fb/0Iy1uU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UPP8GvCKB+mgfA+fcbxtDk4nJe4vnnacCWsm/uL9g9AJE1HOFvKz8OT5y6MdI4oVDO+7eLIYudK1F5Bt0pJB7B7E5yI/Hzn5TQjDAsFVebtDQXiQMk21EAAnZFUr9qED45PO8sKVt8dFZJ5pd4Qaerp26MLssQTY11GDFUUfh4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zxw+XbHn; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zxw+XbHn" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-8249aca0affso1801568b3a.3 for ; Sun, 22 Feb 2026 06:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771772033; x=1772376833; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=epDmMCbVsSVX/Bna9dzyFpbWPHgpZr4iYJuReaSql4I=; b=Zxw+XbHnRh2JY/QUMqEir+gZxrVfWklKwvOsSrqNvgXz4AiQMSR1T6JxBIkI3TEkj1 fGEL9k05amR70CGdAvtKYtgCXjbx4jck+3XuKpyeREKdKJTATvB32fnJlL66wTVcq1Dx MGet915PqAYMgRhQoLSn6ScJFy08Ikxg8SboTFhk2X5qrscMcV0RtOnNYFNGnjEFWKjL OnMqALYW1qu3qvZFSf/WlgUIFCDXVFd/SpGRasYxR5BE+CY2UoM/KFFNZtAk32kq6Psb 3qG3y3bfaf3R3qaCKNx0EUAosFt/uZgC4SVoLf6h87ocMvlQPVy0n6yByZuEjU3yi2AX C7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771772033; x=1772376833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=epDmMCbVsSVX/Bna9dzyFpbWPHgpZr4iYJuReaSql4I=; b=pNLanakyGiYMDcldEK5ef4lVk9K2H3O7MngmXYiqMJJHKiJp3m3+KRKTLg8g9whSrw FTHuCI8bPhChnhgPpbiWp13H+YrxRJj0xPD5agP4yGPvihRLxe3nBWfGbFvdpTfBUgEv 9LLhlQala9CnGIDcUqGL07OK4vmJZeWcw/KInu6AH61LkSQP4uqR4vJjt0lxUVnvuhFq gzzTEbE4geI9TOGFkrgXovIOBde+rt9qSvpbSDmqf5+lwygq6mJLsO15ww2LQi9Aekve o081Yb9hM+OSbaICXVGOPW111Ry0EWtpzR1DsAP3xcmzj9filK3L91jbl1drHJgPw78q gwJA== X-Forwarded-Encrypted: i=1; AJvYcCVllbyVb1jHrVzg6ljFwI8qJ0y+HySS4qUJvNosNh/egniTRP0unycXHh48bRkzhlmUGstytzNNAy8VE2g=@vger.kernel.org X-Gm-Message-State: AOJu0YzmYVCq87dwhRGik5M4wXMge2Xzbt5DY6UGA5hse1W9gmsROwqc JRjcB9f/e8q8GbMpSb9qHoW9VHc5SZYV+bzw5BtIKRQYQqzD+KrbtDTvQ3orrQ== X-Gm-Gg: AZuq6aInJDFMRY6cYHHvwMbVGOkDwllD4BWxFAN+aGGjHLWDFe46Wbjc3gVUAZfZX3J dKyGllCRcz9K/hm0x5/XzfUEOfaZOV3osrj2js4rpLlaeOVahl/FEYmghB4/gdMtzWrDRmXPWsL gBRbh/dDCMcw35seNoAyHkdYYcLI06MrrJcg8nq30Y7bXG2k1h4G75bU2N+pcOwaPUGZx7nTqBV vOGSFHyVUr57N2WL0Qmi/878gUtS1DpOLEufG09+6AZdoKs8V0ngvsUiJmGqJ0skZNPGNdQ1F9t iZgiZ5QUlYtBDrpoPP3ua8wwy/XpbfEKxRD8JAY42/vAGVlNeNAHkFtn0riiUwVDMHmTKLiBY9f IUYR/eOujvFZ+Q+gniBzdCCHmgc3aB2TvpWhPu9+r5GuEdsRkdgEY35j0OxSxriFAcRLzN8yhe4 Y32jJOL3bYjKn3nFbLBKISeydcT+oBdGY1DiaWOKVnm4BNrh7nuSdVmrlaLYRP58n2x67PaIpEy Q== X-Received: by 2002:a05:6a00:2d13:b0:823:c59:9cb0 with SMTP id d2e1a72fcca58-826da8b41d2mr4650148b3a.1.1771772033273; Sun, 22 Feb 2026 06:53:53 -0800 (PST) Received: from mm2dtv09.. (61-216-20-61.hinet-ip.hinet.net. [61.216.20.61]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-826dd6c601esm4859766b3a.29.2026.02.22.06.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Feb 2026 06:53:52 -0800 (PST) From: Kenny Cheng 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 Subject: [PATCH v2] of: fix incorrect device creation for reserved memory nodes Date: Sun, 22 Feb 2026 22:53:21 +0800 Message-Id: <20260222145321.1736481-1-chao.shun.cheng.tw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260222144507.1736070-1-chao.shun.cheng.tw@gmail.com> References: <20260222144507.1736070-1-chao.shun.cheng.tw@gmail.com> 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 Content-Type: text/plain; charset="utf-8" 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 --- v2: - Fix missing variable declaration for 'reserved'. --- drivers/of/platform.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index ba591fbceb56..68bba234cbea 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -500,7 +500,7 @@ static const struct of_device_id reserved_mem_matches[]= =3D { =20 static int __init of_platform_default_populate_init(void) { - struct device_node *node; + struct device_node *node, *reserved; =20 device_links_supplier_sync_state_pause(); =20 @@ -563,8 +563,17 @@ static int __init of_platform_default_populate_init(vo= id) * 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 =3D 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); + } =20 node =3D of_find_node_by_path("/firmware"); if (node) { --=20 2.34.1