From patchwork Wed Dec 18 02:44:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hattori X-Patchwork-Id: 2024720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=xiBS1750; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-4386-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YCdLl44jjz1yQN for ; Wed, 18 Dec 2024 13:44:47 +1100 (AEDT) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 54A251663BA for ; Wed, 18 Dec 2024 02:44:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C6F1153835; Wed, 18 Dec 2024 02:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b="xiBS1750" X-Original-To: linux-tegra@vger.kernel.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 A421513AA53 for ; Wed, 18 Dec 2024 02:44:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734489885; cv=none; b=VBZapAl64XCqCqQWinQwC94PwaO+CXGncyRcDhfxyYqUivsOhQ2KhE/RkPgGKd9yrpZg3MO4vomaEJWEPs88+JcBdLfo0X4rv5Eot1y7BBZzcOFdQLqgm43EbDBSyuvylo/CQSN8fhI29eI0uuAJqSPBdFRW2bBWRVT7NsoFtog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734489885; c=relaxed/simple; bh=8klLqyCSX5VssUWCGfWkVvIxIwXijwTHWvuTG5U+If8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UJCm3crYGiFOJmf61qpxMANP2JUX1UbHTWNI1nxPovanttuBgdhu+eFnmn3998ZghvE+9oU1bQDRNJNdrCIIgxQO8z6nK7RRiwp1rxlR1vLtuobUTMBsnBuKxUJkVfNbUqI8m0c/XRUR6Wm7eNf8KGDIFlojrVxfCtj5ILBruh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b=xiBS1750; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-215770613dbso40750835ad.2 for ; Tue, 17 Dec 2024 18:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com; s=20230601; t=1734489883; x=1735094683; 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=vWpP8EEP0IJjqZcRfsJULWXauzW58oHVw0gt4bL9lEg=; b=xiBS1750UOFDUOSr8zfL2NEAVFbIabSWsdPXrnmuXiooH9HVDRajApym0AKkJlCG2v cwIzrKDPlJOib014/+F4yoEpyIY19tmSF6YRTiTSJlNsaUhjy0q8xkR4wOMHA1vRjXLU y0io6gcopPz522jzYVBbcmYsX3GzHOMTmxWBIBy4zI2+dj9/s1vz3S24yt1KuLSShkpd JxpWfVCWHn7WdieC3QldvSJAO9wJuEkwKPF4orxHuPIW2vzBdD39cCgANNwdwXF9NOMs FKP2gMM/SqsAazJ+h62kjTOt45HVvwckcgbBkL4ODeLMD+ANkGuHrr7nsMzEt/IHgxxY x2Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734489883; x=1735094683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vWpP8EEP0IJjqZcRfsJULWXauzW58oHVw0gt4bL9lEg=; b=YFNtWrgry8Dj7zIJmhWWVCh0xvYyyWd0HlSnkzlwdEdYTZTsYq2uDZonf0wpz5gM7l m+fi/brgYRx4ElhxBf8PL3Oq+RtXnUUSJLrhKVRl4sRCX+zUWEsvP0whYiAEZ6QD7SwX t7fHdo6IRxqQ6Lt7IlC4elZirp9flCgV00BMmOmiTvk/qvdFfD5yFK9l1548Bosmp86q zY3BXK273LELv4IuNaBiHoGRhE4cb97lUyzEoxAYu1cGehS4cuHO/6H8ZBRenjwv3fWq GQs6R31B6376l9bEVaxe8XAkRqkW1pCIDhTdSF1A4CNUk7X0GQpQlJUYGYh7DHSXf++C izTw== X-Gm-Message-State: AOJu0Yw0KP9U/g1OIs0kUBlWuXnAKQUhriDht85+PohsrgLPUAO/eQYT ulXiyAU0VlB4zypSocvKtcJ+XEq06qNgwP4vlndYqt4GCObGnHkJGcHFn1Y/9/k= X-Gm-Gg: ASbGncsMIu8TCZgPK9B2sXvY3r838Hj2qPhKiGL/ZeGLXNRnVDdlyfcQyVtqi4hPzIB W3CNC3VcQlgZSoDSDPoNWV7MKdSQM4D8Si8j+XurQogDKWzZ0E0fO1K7U8IUSiziia0zi8WgV2/ yOv8R25bV2c55u8uiK1tHt8nP/otJxu6K7rY4W/4F/n1Q6d8luhNpab7TRNnvaJ8ZYu+LniAqnW +5IrmcSj1AQr8qaJ+04mXpzoLEa2EntT8h8mL+Gee0/0UVwnO8cexlI2ilCjAruNN50hzm5HIer f3+UensAo0HjUDEiV+zqY6Ivjb6POkOyuHrX2v7O6v4= X-Google-Smtp-Source: AGHT+IGMu4Qyldx7xp6+Pi+DA9ILuLCuP3UeF08n9DsTL0S2PpFfbjHYlX7csZNN9TOHlkkfIwv5wA== X-Received: by 2002:a17:902:fac5:b0:216:6769:9ed7 with SMTP id d9443c01a7336-218d724960fmr15489515ad.40.1734489883011; Tue, 17 Dec 2024 18:44:43 -0800 (PST) Received: from localhost.localdomain (133-32-227-190.east.xps.vectant.ne.jp. [133.32.227.190]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e64085sm66229375ad.233.2024.12.17.18.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 18:44:42 -0800 (PST) From: Joe Hattori To: krzk@kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com Cc: linux-tegra@vger.kernel.org, dan.carpenter@linaro.org, Joe Hattori Subject: [PATCH v2 1/2] memory: tegra20-emc: fix an OF node reference bug in tegra_emc_find_node_by_ram_code() Date: Wed, 18 Dec 2024 11:44:14 +0900 Message-Id: <20241218024415.2494267-2-joe@pf.is.s.u-tokyo.ac.jp> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241218024415.2494267-1-joe@pf.is.s.u-tokyo.ac.jp> References: <20241218024415.2494267-1-joe@pf.is.s.u-tokyo.ac.jp> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As of_find_node_by_name() release the reference of the argument OF node, tegra_emc_find_node_by_ram_code() releases some OF nodes while still in use, resulting in possible UAFs. Avoid calling of_node_put() at the end of the loop, and call of_node_get() before some calls of of_find_node_by_name(). This bug was found by an experimental verification tool that I am developing. Fixes: 96e5da7c8424 ("memory: tegra: Introduce Tegra20 EMC driver") Signed-off-by: Joe Hattori --- drivers/memory/tegra/tegra20-emc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c index 7193f848d17e..fef54179ddee 100644 --- a/drivers/memory/tegra/tegra20-emc.c +++ b/drivers/memory/tegra/tegra20-emc.c @@ -474,6 +474,7 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc) ram_code = tegra_read_ram_code(); + of_node_get(dev->of_node); for (np = of_find_node_by_name(dev->of_node, "emc-tables"); np; np = of_find_node_by_name(np, "emc-tables")) { err = of_property_read_u32(np, "nvidia,ram-code", &value); @@ -481,6 +482,7 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc) struct device_node *lpddr2_np; bool cfg_mismatches = false; + of_node_get(np); lpddr2_np = of_find_node_by_name(np, "lpddr2"); if (lpddr2_np) { const struct lpddr2_info *info; @@ -518,7 +520,6 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc) } if (cfg_mismatches) { - of_node_put(np); continue; } } From patchwork Wed Dec 18 02:44:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hattori X-Patchwork-Id: 2024721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=T9h3EQT2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-4387-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YCdLq1sQxz1yQN for ; Wed, 18 Dec 2024 13:44:51 +1100 (AEDT) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 15244165E53 for ; Wed, 18 Dec 2024 02:44:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BE4613BAEE; Wed, 18 Dec 2024 02:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b="T9h3EQT2" X-Original-To: linux-tegra@vger.kernel.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 0E0C013B58F for ; Wed, 18 Dec 2024 02:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734489889; cv=none; b=YGcJJPOGPIIQ5ys04KGqtbOViZBpNlg6SgfJZDKfZXbEARmwEDGml20YtuG2oYlIFwmXx8i7XGLg1ttvBEZSqPQxY4/LWJW4A4xek6tZKQVxn2chXofzWjsqKNjZS+c3sfDguJUU86B5jfXZNWtiL909pBXGtviJRFNDq6dcpuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734489889; c=relaxed/simple; bh=hbpvzrSeRO8zhRvJBPn1crrG5ctE/FwuugKGi7ydP1M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JlZSITixuqrBuUs0+eSKBHpD0C7jVcdpjIufYEG/nXQk+uILNejSKcXdeGhiKaxKNl1EAEjoU3o4WBF/XG3mKXuuxQxx7N9kPMlRhHHGDPFJ8w3zNO8WN2kI2JupnZz5JY2ecVnBPLHwA4yoGd/KFfdR7i1dZA0tyt77hxoWMQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b=T9h3EQT2; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21675fd60feso62312615ad.2 for ; Tue, 17 Dec 2024 18:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com; s=20230601; t=1734489886; x=1735094686; 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=AQPyW4IXQjQOJWJUVZxyXa86Uk2SzO89MoYH8BTOG8w=; b=T9h3EQT2oojA+4y90OcIduhoM2yBKVl7GN62FCvH9ZZ9AgWGb7Htgofq/RHXoCb0BH 1JgotmEyJwhHMh4c1Bm3BtRi+LdDUj/f51RPWLzRsnMQ3jVz7DyP9817uxzhOwi7z8Rv 5+v3UOKLx4SrJoArR27fetnjgKYuFxYwggVntGGTx1KYcFFKQO4fI71wcZFnhUfXxIto Ma+Z9cFTyk0x1e6u1xZosQO0augBZNj1NXD0+++yxv/mB2/nqB2Ix1iQwM5tKybJewtu z3GCD91O99cyyNWF/Y24pbnwTJ/CiLfkoLPMQ0VL0DQBlcD2g5vhvxDhvYuZ8CnOB2Qu 7fvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734489886; x=1735094686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AQPyW4IXQjQOJWJUVZxyXa86Uk2SzO89MoYH8BTOG8w=; b=WL5W1T5hdVgltDUv5aM0Gb0DfKBxs6vNrHGAeCgLGcsbmLdpZ1yFK+RDlcwHXOjG4g K5BVCC1Gf3YVafOtZi+MMquURl3YGFJtjyvGwpMCTxIqBEosmxkHZ/nooV1cPMdKAXBE anVIvcfhapPDA1nA8C3IYKnqEp+aa9h06636kCWGUREp9Npx9laT+uShABAxL7Pp21Ry X6wPrpagWlPcs3H8BVEO6fm0i8KR2CgyO3fM2UztDSxETK0ZyOOWxUeCM/4KEDfjxcsN E/l0dBS/237P6dT5CSL1azfVtaTgeBdwMjit8qfPNWkF3bdRHpanf19jHkMo2Iz0UEyk 723Q== X-Gm-Message-State: AOJu0YzNz+s/BLguIl08e1xwYBMnq/x3wAwU7EH5M/w3wxaRgXRdsCy4 HKTCvzaEJDPsvDUM8he/AFN1bugHxYNva8KGPYXIzIZuw7X136oi9kWdseT6sGo= X-Gm-Gg: ASbGncsEJLRBEIRxMQbKxMam2o9w1NuvDX7Ib+dZbMJ2qRzQI5QfYW5dwSwFSjQP/gG vpUAGd8Csz+mQfnvlJpFBgf6Vj5z2PmvggK9rN2/GHIoG8404vTl/E1mimBnoquR/LEL118REBn B9VlgJjbkJUXUuA/Sih7T4jfgH7skFNJ/Al4ZhMD7cmzsdtX2zw1INV9jodTe5jgn+CUPIuhb4P VGmLiV9Sico3DWKf5ql9BJGyvojlr9A63Ik1AnuRVlsU9XBEuGEOA0RmMQdg1ekI8+8MEdKwJ6d 3PF56lVZlaWAwQ1nOUmovxS5nbGngMJ3onqmxet+Ln4= X-Google-Smtp-Source: AGHT+IFuJ2PTbr4zGJ8NwLbX+dJZj1lBHIE/U1NBCfhL0uZ2E5+U+8wUMD82b4o3nUf7wKjXOeXOLA== X-Received: by 2002:a17:902:d4ca:b0:216:61d2:46b6 with SMTP id d9443c01a7336-218d71051eamr13946835ad.25.1734489886270; Tue, 17 Dec 2024 18:44:46 -0800 (PST) Received: from localhost.localdomain (133-32-227-190.east.xps.vectant.ne.jp. [133.32.227.190]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e64085sm66229375ad.233.2024.12.17.18.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 18:44:45 -0800 (PST) From: Joe Hattori To: krzk@kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com Cc: linux-tegra@vger.kernel.org, dan.carpenter@linaro.org, Joe Hattori Subject: [PATCH v2 2/2] memory: tegra20-emc: reflect the DT hierarchy when finding OF nodes in tegra_emc_find_node_by_ram_code() Date: Wed, 18 Dec 2024 11:44:15 +0900 Message-Id: <20241218024415.2494267-3-joe@pf.is.s.u-tokyo.ac.jp> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241218024415.2494267-1-joe@pf.is.s.u-tokyo.ac.jp> References: <20241218024415.2494267-1-joe@pf.is.s.u-tokyo.ac.jp> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to the yaml file [1] and the dts files [2-4], the "emc-tables" node is a child of a node with the property "nvidia,use-ram-code", and the "lpddr2" node is a child of the "emc-tables" node. Thus utilize the for_each_child_of_node() macro and of_get_child_by_name() instead of of_find_node_by_name() to simplify the code. This bug was found by an experimental verification tool that I am developing. [1]: Documentation/devicetree/bindings/memory-controllers/nvidia,tegra20-emc.yaml [2]: arch/arm/boot/dts/nvidia/tegra20-acer-a500-picasso.dts [3]: arch/arm/boot/dts/nvidia/tegra20-asus-tf101.dts [4]: arch/arm/boot/dts/nvidia/tegra20-paz00.dts Signed-off-by: Joe Hattori --- drivers/memory/tegra/tegra20-emc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c index fef54179ddee..9b7d30a21a5b 100644 --- a/drivers/memory/tegra/tegra20-emc.c +++ b/drivers/memory/tegra/tegra20-emc.c @@ -474,16 +474,15 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc) ram_code = tegra_read_ram_code(); - of_node_get(dev->of_node); - for (np = of_find_node_by_name(dev->of_node, "emc-tables"); np; - np = of_find_node_by_name(np, "emc-tables")) { + for_each_child_of_node(dev->of_node, np) { + if (!of_node_name_eq(np, "emc-tables")) + continue; err = of_property_read_u32(np, "nvidia,ram-code", &value); if (err || value != ram_code) { struct device_node *lpddr2_np; bool cfg_mismatches = false; - of_node_get(np); - lpddr2_np = of_find_node_by_name(np, "lpddr2"); + lpddr2_np = of_get_child_by_name(np, "lpddr2"); if (lpddr2_np) { const struct lpddr2_info *info;