Skip to contentSkip to conversation

ARM: OMAP2+: Hold reference returned from of_find_xxx API

PATCH Superseded Liang He 2 participants 3 messages Sep 15, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 ARM: OMAP2+: Hold reference returned from of_find_xxx API

In omap4_twl_init(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes ccd369455a23 ("ARM: OMAP2+: Remove bogus warnings for machines without twl PMIC")
---
 arch/arm/mach-omap2/omap_twl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap_twl.c +4 -2
index d4dab041324d..07b5f17066ce 100644
@@ -213,11 +213,13 @@ static struct omap_voltdm_pmic omap4_core_pmic = {
 int __init omap4_twl_init(void)
 {
 	struct voltagedomain *voltdm;
+	struct device_node *np;
 
 	if (!cpu_is_omap44xx() ||
-	    of_find_compatible_node(NULL, NULL, "motorola,cpcap"))
+	    (np = of_find_compatible_node(NULL, NULL, "motorola,cpcap"))) {
+		of_node_put(np);
 		return -ENODEV;
-
+	}
 	voltdm = voltdm_lookup("mpu");
 	omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 16 lines · Liang He

In omap4_twl_init(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes ccd369455a23 ("ARM: OMAP2+: Remove bogus warnings for machines without twl PMIC")
---
 arch/arm/mach-omap2/omap_twl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap_twl.c +0 -0
index d4dab041324d..07b5f17066ce 100644

arch/arm/mach-omap2/omap_twl.c static struct omap_voltdm_pmic omap4_core_pmic = { · line 220

Quoted 9 lines
arch/arm/mach-omap2/omap_twl.c +3 -1
@@ -213,11 +213,13 @@ static struct omap_voltdm_pmic omap4_core_pmic = {
 int __init omap4_twl_init(void)
 {
 	struct voltagedomain *voltdm;
+	struct device_node *np;
 
 	if (!cpu_is_omap44xx() ||
-	    of_find_compatible_node(NULL, NULL, "motorola,cpcap"))
+	    (np = of_find_compatible_node(NULL, NULL, "motorola,cpcap"))) {
+		of_node_put(np);

This is buggy - if cpu_is_omap44xx() is false, then np will not be initialised. The simple solution is to initialise np to NULL.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
author
#2 lore raw
Quoted 22 lines · Russell King (Oracle)
Quoted 21 lines · Liang He

In omap4_twl_init(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes ccd369455a23 ("ARM: OMAP2+: Remove bogus warnings for machines without twl PMIC")
---
 arch/arm/mach-omap2/omap_twl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/omap_twl.c +1 -0
index d4dab041324d..07b5f17066ce 100644
@@ -213,11 +213,13 @@ static struct omap_voltdm_pmic omap4_core_pmic = {
 int __init omap4_twl_init(void)
 {
 	struct voltagedomain *voltdm;
+	struct device_node *np;
 
Quoted 8 lines

arch/arm/mach-omap2/omap_twl.c static struct omap_voltdm_pmic omap4_core_pmic = { · line 220

Quoted 4 lines
arch/arm/mach-omap2/omap_twl.c +2 -1
 	if (!cpu_is_omap44xx() ||
-	    of_find_compatible_node(NULL, NULL, "motorola,cpcap"))
+	    (np = of_find_compatible_node(NULL, NULL, "motorola,cpcap"))) {
+		of_node_put(np);

This is buggy - if cpu_is_omap44xx() is false, then np will not be initialised. The simple solution is to initialise np to NULL.

Thanks, I will send a new version soon.

Liang

Quoted 3 lines
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel