Skip to contentSkip to conversation

net: hns: hns_enet: Add of_node_put in hns_nic_dev_probe()

PATCH In review Nishka Dasgupta 2 participants 2 messages Aug 15, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: hns: hns_enet: Add of_node_put in hns_nic_dev_probe()

The local variable ae_node in function hns_nic_dev_probe takes the return value of of_parse_phandle, which gets a node but does not put it. This may cause a memory leak. Hence put ae_node after the last time it is invoked.
Issue found with Coccinelle.

---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/hisilicon/hns/hns_enet.c +1 -0
index 2235dd55fab2..b26e84929e1e 100644
@@ -2309,6 +2309,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
 			goto out_read_prop_fail;
 		}
 		priv->fwnode = &ae_node->fwnode;
+		of_node_put(ae_node);
 	} else if (is_acpi_node(dev->fwnode)) {
 		struct fwnode_reference_args args;
 
Signature · 1 line
2.19.1
#1 lore raw
Quoted 17 lines · Nishka Dasgupta

The local variable ae_node in function hns_nic_dev_probe takes the return value of of_parse_phandle, which gets a node but does not put it. This may cause a memory leak. Hence put ae_node after the last time it is invoked.
Issue found with Coccinelle.

---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/hisilicon/hns/hns_enet.c +0 -0
index 2235dd55fab2..b26e84929e1e 100644

drivers/net/ethernet/hisilicon/hns/hns_enet.c static int hns_nic_dev_probe(struct platform_device *pdev) · line 2315

Quoted 7 lines
drivers/net/ethernet/hisilicon/hns/hns_enet.c +1 -0
@@ -2309,6 +2309,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
 			goto out_read_prop_fail;
 		}
 		priv->fwnode = &ae_node->fwnode;
+		of_node_put(ae_node);
 	} else if (is_acpi_node(dev->fwnode)) {
 		struct fwnode_reference_args args;
 

Hi, Nishka:
This patch is wrong, we put the node in hns_nic_dev_remove().

The following patch had solved this problem:
263c6d75f9a5 (net: hns: Fix for missing of_node_put() after of_parse_phandle())