[PATCH v2] arm/mach: Hold reference returned by of_find_xxx APIs

Liang He windhl at 126.com
Mon Jun 27 22:57:13 PDT 2022


In highbank_init_irq(), tegra_init_irq() and omap4_cpcap_init(),
we should hold the reference returned by of_find_xxx APIs and
use it to call of_node_put() for refcount balance.

Signed-off-by: Liang He <windhl at 126.com>
---
 v2: use 'check-and-put' coding style
 v1: fix bugs but with 'check-after-put'
 v1-link: https://lore.kernel.org/all/20220621091937.4082422-1-windhl@126.com/

 patch-code have been compiled test with multi_v7_defconfig

 arch/arm/mach-highbank/highbank.c | 7 ++++++-
 arch/arm/mach-omap2/pmic-cpcap.c  | 5 ++++-
 arch/arm/mach-tegra/irq.c         | 6 +++++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-highbank/highbank.c b/arch/arm/mach-highbank/highbank.c
index db607955a7e4..2a74f7dfb1d4 100644
--- a/arch/arm/mach-highbank/highbank.c
+++ b/arch/arm/mach-highbank/highbank.c
@@ -50,10 +50,15 @@ static void highbank_l2c310_write_sec(unsigned long val, unsigned reg)
 
 static void __init highbank_init_irq(void)
 {
+	struct device_node *np;
+
 	irqchip_init();
 
-	if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9"))
+	np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9");
+	if (np) {
 		highbank_scu_map_io();
+		of_node_put(np);
+	}
 }
 
 static void highbank_power_off(void)
diff --git a/arch/arm/mach-omap2/pmic-cpcap.c b/arch/arm/mach-omap2/pmic-cpcap.c
index 668dc84fd31e..75abc54103db 100644
--- a/arch/arm/mach-omap2/pmic-cpcap.c
+++ b/arch/arm/mach-omap2/pmic-cpcap.c
@@ -238,9 +238,12 @@ static struct omap_voltdm_pmic omap4_fan_iva = {
 int __init omap4_cpcap_init(void)
 {
 	struct voltagedomain *voltdm;
+	struct device_node *np;
 
-	if (!of_find_compatible_node(NULL, NULL, "motorola,cpcap"))
+	np = of_find_compatible_node(NULL, NULL, "motorola,cpcap");
+	if (!np)
 		return -ENODEV;
+	of_node_put(np);
 
 	voltdm = voltdm_lookup("mpu");
 	omap_voltage_register_pmic(voltdm, &omap443x_max8952_mpu);
diff --git a/arch/arm/mach-tegra/irq.c b/arch/arm/mach-tegra/irq.c
index 4e1ee70b2a3f..d59f1789435c 100644
--- a/arch/arm/mach-tegra/irq.c
+++ b/arch/arm/mach-tegra/irq.c
@@ -88,8 +88,12 @@ static const struct of_device_id tegra_ictlr_match[] __initconst = {
 
 void __init tegra_init_irq(void)
 {
-	if (WARN_ON(!of_find_matching_node(NULL, tegra_ictlr_match)))
+	struct device_node *np;
+
+	np = of_find_matching_node(NULL, tegra_ictlr_match);
+	if (WARN_ON(!np))
 		pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
+	of_node_put(np);
 
 	tegra114_gic_cpu_pm_registration();
 }
-- 
2.25.1




More information about the linux-arm-kernel mailing list