Skip to contentSkip to conversation

cxl: Fix refcount leak in cxl_calc_capp_routing

PATCH Applied Miaoqian Lin 5 participants 6 messages Jun 5, 2022 – Nov 30, 2022 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl: Fix refcount leak in cxl_calc_capp_routing

of_get_next_parent() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

Fixes f24be42aab37 ("cxl: Add psl9 specific code")
---
 drivers/misc/cxl/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
index 3de0aea62ade..62385a529d86 100644
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
 	rc = get_phb_index(np, phb_index);
 	if (rc) {
 		pr_err("cxl: invalid phb index\n");
+		of_node_put(np);
 		return rc;
 	}
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Miaoqian Lin

of_get_next_parent() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

Fixes f24be42aab37 ("cxl: Add psl9 specific code")

Indeed. Thanks!

Fred

Quoted 16 lines
---
  drivers/misc/cxl/pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
index 3de0aea62ade..62385a529d86 100644
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
  	rc = get_phb_index(np, phb_index);
  	if (rc) {
  		pr_err("cxl: invalid phb index\n");
+		of_node_put(np);
  		return rc;
  	}
 
Acked-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 9 lines · Miaoqian Lin

of_get_next_parent() returns a node pointer with refcount incremented,
we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

Fixes f24be42aab37 ("cxl: Add psl9 specific code")

Thanks!

Quoted 17 lines

---
 drivers/misc/cxl/pci.c | 1 +

 1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
index 3de0aea62ade..62385a529d86 100644
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev,
 u64 *chipid,
         rc = get_phb_index(np, phb_index);
         if (rc) {
                 pr_err("cxl: invalid phb index\n");
+               of_node_put(np);
                 return rc;
         }

#3 lore raw

Should this be applied by Bjorn as most recent changes to that file ?

Le 14/06/2022 à 12:12, Andrew Donnellan a écrit :

Quoted 34 lines · Miaoqian Lin
Quoted 9 lines

of_get_next_parent() returns a node pointer with refcount incremented,
we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

Fixes f24be42aab37 ("cxl: Add psl9 specific code")

Thanks!

Quoted 17 lines
---
  drivers/misc/cxl/pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
index 3de0aea62ade..62385a529d86 100644
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev,
 u64 *chipid,
         rc = get_phb_index(np, phb_index);
         if (rc) {
                 pr_err("cxl: invalid phb index\n");
+               of_node_put(np);
                 return rc;
         }
#4 lore raw
Quoted 1 line · Christophe Leroy

Should this be applied by Bjorn as most recent changes to that file ?

We usually take cxl patches through powerpc, though sometimes Greg picks them up through char-misc.

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#5 lore raw
In reply to Miaoqian Lin
Quoted 8 lines · Miaoqian Lin

of_get_next_parent() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

[...]

Applied to powerpc/next.

[1/1] cxl: Fix refcount leak in cxl_calc_capp_routing

      https://git.kernel.org/powerpc/c/1d09697ff22908ae487fc8c4fbde1811732be523

cheers