Skip to contentSkip to conversation

net: Fix 2 OF device node refcount leakage issues

PATCH In review Zijun Hu 2 participants 5 messages Dec 12, 2024 – Dec 13, 2024

Subsystems (4)
lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

cover net: Fix 2 OF device node refcount leakage issues

This patch series is to fix 2 OF device node refcount leakage issues.

---
Zijun Hu (2):
net: pse-pd: tps23881: Fix device node refcount leakage in tps23881_get_of_channels()
net: bcmasp: Fix device node refcount leakage in bcmasp_probe()

 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 1 +
 drivers/net/pse-pd/tps23881.c               | 1 +
 2 files changed, 2 insertions(+)

---
base-commit: ff7afaeca1a15fbeaa2c4795ee806c0667bd77b2
change-id: 20241206-drivers_fix-735f56ed5ec7

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
author
#1 lore raw

PATCH 1/2 net: pse-pd: tps23881: Fix device node refcount leakage in tps23881_get_of_channels()

From: Zijun Hu <[email protected]>

tps23881_get_of_channels() invokes of_find_node_by_name(@priv->np, ...) and the callee will put OF device node @priv->np refcount, but the caller does not compensate the refcount before the invocation, so causes the node refcount leakage.

Fix by of_node_get(@priv->np) before the invocation.

Fixes 20e6d190ffe1 ("net: pse-pd: Add TI TPS23881 PSE controller driver")
---
 drivers/net/pse-pd/tps23881.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pse-pd/tps23881.c +1 -0
index 5c4e88be46ee3316330e26a68d06540ff1db86ff..f5c04dd5be379f7b9697e067a32d59028f446088 100644
@@ -216,6 +216,7 @@ tps23881_get_of_channels(struct tps23881_priv *priv,
 	if (!priv->np)
 		return -EINVAL;
 
+	of_node_get(priv->np);
 	channels_node = of_find_node_by_name(priv->np, "channels");
 	if (!channels_node)
 		return -EINVAL;
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 net: bcmasp: Fix device node refcount leakage in bcmasp_probe()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

bcmasp_probe() invokes of_find_node_by_name(@dev->of_node, ...) and the callee will put OF device node @dev->of_node refcount, but the caller does not compensate the refcount before the invocation, so causes the node refcount leakage.

Fix by of_node_get(@dev->of_node) before the invocation.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +1 -0
index 297c2682a9cf979fbc4af211139f1b1ed0df01d5..517593c5894568111111aff0f6919fb02d780c85 100644
@@ -1367,6 +1367,7 @@ static int bcmasp_probe(struct platform_device *pdev)
 	bcmasp_core_init(priv);
 	bcmasp_core_init_filters(priv);
 
+	of_node_get(dev->of_node);
 	ports_node = of_find_node_by_name(dev->of_node, "ethernet-ports");
 	if (!ports_node) {
 		dev_warn(dev, "No ports found\n");
Signature · 1 line
2.34.1
maintainer
#3 lore raw
In reply to Zijun Hu
Quoted 8 lines · On Thu, 12 Dec 2024 23:06:53 +0800 Zijun Hu <[email protected]> wrote:

This patch series is to fix 2 OF device node refcount leakage issues.

---
Zijun Hu (2):
net: pse-pd: tps23881: Fix device node refcount leakage in
tps23881_get_of_channels() net: bcmasp: Fix device node refcount leakage in bcmasp_probe()

Thanks for the patch. This fix was already sent by Zhang Zekun:
https://lore.kernel.org/netdev/[email protected]/

net maintainers would prefer to have the API changed as calling of_node_get before of_find_node_by_name is not intuitive.

Still, don't know if we should fix it until the API is changed?

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
author
#4 lore raw
Quoted 12 lines · Kory Maincent
Quoted 8 lines · On Thu, 12 Dec 2024 23:06:53 +0800 Zijun Hu <[email protected]> wrote:

This patch series is to fix 2 OF device node refcount leakage issues.

---
Zijun Hu (2):
net: pse-pd: tps23881: Fix device node refcount leakage in
tps23881_get_of_channels() net: bcmasp: Fix device node refcount leakage in bcmasp_probe()

Quoted 3 lines

Thanks for the patch. This fix was already sent by Zhang Zekun:
https://lore.kernel.org/netdev/[email protected]/

thank you for sharing this info.

Quoted 3 lines

net maintainers would prefer to have the API changed as calling of_node_get before of_find_node_by_name is not intuitive.

agree.

Quoted 2 lines

Still, don't know if we should fix it until the API is changed?

(^^)

Quoted 1 line

Regards,