Skip to contentSkip to conversation

crypto: nx: Hold the reference returned by of_find_compatible_node

PATCH In review Liang He 2 participants 5 messages Jul 1, 2022 – Jul 4, 2022

Subsystems (7)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/3 crypto: nx: Hold the reference returned by of_find_compatible_node

In nx842_pseries_init(), we should hold the reference returned by of_find_compatible_node() and use it to call of_node_put to keep refcount balance.

---
 drivers/crypto/nx/nx-common-pseries.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/crypto/nx/nx-common-pseries.c +4 -1
index 7584a34ba88c..3ea334b7f820 100644
@@ -1208,10 +1208,13 @@ static struct vio_driver nx842_vio_driver = {
 static int __init nx842_pseries_init(void)
 {
 	struct nx842_devdata *new_devdata;
+	struct device_node *np;
 	int ret;
 
-	if (!of_find_compatible_node(NULL, NULL, "ibm,compression"))
+	np = of_find_compatible_node(NULL, NULL, "ibm,compression");
+	if (!np)
 		return -ENODEV;
+	of_node_put(np);
 
 	RCU_INIT_POINTER(devdata, NULL);
 	new_devdata = kzalloc(sizeof(*new_devdata), GFP_KERNEL);
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/3 arm: omap2: pm33xx-core: Fix missing of_node_put() in amx3_idle_init()

To keep refcount balance, we need to call of_node_put() for the reference 'state_node' returned by of_parse_phandle() in fail path or when it is not used anymore.

---
 arch/arm/mach-omap2/pm33xx-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/pm33xx-core.c +5 -1
index bf0d25fd2cea..58b98a17746c 100644
@@ -393,12 +393,15 @@ static int __init amx3_idle_init(struct device_node *cpu_node, int cpu)
 		if (!state_node)
 			break;
 
-		if (!of_device_is_available(state_node))
+		if (!of_device_is_available(state_node)) {
+			of_node_put(state_node);
 			continue;
+		}
 
 		if (i == CPUIDLE_STATE_MAX) {
 			pr_warn("%s: cpuidle states reached max possible\n",
 				__func__);
+			of_node_put(state_node);
 			break;
 		}
 
@@ -408,6 +411,7 @@ static int __init amx3_idle_init(struct device_node *cpu_node, int cpu)
 			states[state_count].wfi_flags |= WFI_FLAG_WAKE_M3 |
 							 WFI_FLAG_FLUSH_CACHE;
 
+		of_node_put(state_node);
 		state_count++;
 	}
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 3/3 arm: omap2: prm_common: Add the refcount for new reference creation

In reply to Liang He

In omap2_prm_base_init(), for_each_matching_node_and_match() can automatically increase and decrease the refcounting. However, a new reference is escaped out into 'data->np', so we need to use of_node_put() for the old reference and use of_node_get() for the new one.

---
 arch/arm/mach-omap2/prm_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/prm_common.c +2 -1
index fb2d48cfe756..bed151e3f165 100644
@@ -764,7 +764,8 @@ int __init omap2_prm_base_init(void)
 			prm_base.pa = res.start + data->offset;
 		}
 
-		data->np = np;
+		of_node_put(data->np);
+		data->np = of_node_get(np);
 
 		if (data->init)
 			data->init(data);
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH 3/3] arm: omap2: prm_common: Add the refcount for new reference creation

Quoted 16 lines · Liang He

In omap2_prm_base_init(), for_each_matching_node_and_match() can automatically increase and decrease the refcounting. However, a new reference is escaped out into 'data->np', so we need to use of_node_put() for the old reference and use of_node_get() for the new one.

---
 arch/arm/mach-omap2/prm_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/prm_common.c +0 -0
index fb2d48cfe756..bed151e3f165 100644

arch/arm/mach-omap2/prm_common.c int __init omap2_prm_base_init(void) · line 771

Quoted 9 lines
arch/arm/mach-omap2/prm_common.c +2 -1
@@ -764,7 +764,8 @@ int __init omap2_prm_base_init(void)
 			prm_base.pa = res.start + data->offset;
 		}
 
-		data->np = np;
+		of_node_put(data->np);
+		data->np = of_node_get(np);
 
 		if (data->init)
 			data->init(data);

Hmm so I don't get how this improves things? Don't we enable with the same refcounting?

Regards,

Tony

author
#4 lore raw

Re:Re: [PATCH 3/3] arm: omap2: prm_common: Add the refcount for new reference creation

Quoted 30 lines · Tony Lindgren
Quoted 16 lines · Liang He

In omap2_prm_base_init(), for_each_matching_node_and_match() can automatically increase and decrease the refcounting. However, a new reference is escaped out into 'data->np', so we need to use of_node_put() for the old reference and use of_node_get() for the new one.

---
 arch/arm/mach-omap2/prm_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/prm_common.c +0 -0
index fb2d48cfe756..bed151e3f165 100644

arch/arm/mach-omap2/prm_common.c int __init omap2_prm_base_init(void) · line 771

Quoted 9 lines
arch/arm/mach-omap2/prm_common.c +2 -1
@@ -764,7 +764,8 @@ int __init omap2_prm_base_init(void)
 			prm_base.pa = res.start + data->offset;
 		}
 
-		data->np = np;
+		of_node_put(data->np);
+		data->np = of_node_get(np);
 
 		if (data->init)
 			data->init(data);

Hmm so I don't get how this improves things? Don't we enable with the same refcounting?

Quoted 3 lines

Regards,

Tony

Hi, Tony.

Thanks very much for reviewing this patch.

I try to explain as following:

First, there is an old reference (pointer) pointing to device_node A and stored in data->np. Then, in the for_each_xxx iteration, 'np' is a new reference (pointer) pointing to device_node B.

After 'data->np = np' is done, the old reference is destroyed and its refcount should be decreased. Similarly, a new reference to devce_node B is created in 'data->np', so its refcount should be increased.

Sorry if my understanding is wrong or if I do not catch your point.

Thans again,

Liang