Skip to contentSkip to conversation

drivers/net/fs_enet/fs_enet-main.c: Add of_node_put to avoid memory leak

PATCH Applied Julia Lawall 3 participants 3 messages Sep 4, 2010 – Sep 7, 2010

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

PATCH 1/2 drivers/net/fs_enet/fs_enet-main.c: Add of_node_put to avoid memory leak

In this case, a device_node structure is stored in another structure that is then freed without first decrementing the reference count of the device_node structure.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
expression x;
identifier f;
position p1,p2;
@@

x@p1->f = \(of_find_node_by_path\|of_find_node_by_name\|of_find_node_by_phandle\|of_get_parent\|of_get_next_parent\|of_get_next_child\|of_find_compatible_node\|of_match_node\|of_find_node_by_type\|of_find_node_with_property\|of_find_matching_node\|of_parse_phandle\|of_node_get\)(...); ... when != of_node_put(x)
kfree@p2(x)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@
cocci.print_main("call",p1)
cocci.print_secs("free",p2)
// </smpl>

---
 drivers/net/fs_enet/fs_enet-main.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/fs_enet/fs_enet-main.c +2 -1
index d6e3111..d684f18 100644
@@ -1036,7 +1036,7 @@ static int __devinit fs_enet_probe(struct platform_device *ofdev,
 	ndev = alloc_etherdev(privsize);
 	if (!ndev) {
 		ret = -ENOMEM;
-		goto out_free_fpi;
+		goto out_put;
 	}
 
 	SET_NETDEV_DEV(ndev, &ofdev->dev);
@@ -1099,6 +1099,7 @@ out_cleanup_data:
 out_free_dev:
 	free_netdev(ndev);
 	dev_set_drvdata(&ofdev->dev, NULL);
+out_put:
 	of_node_put(fpi->phy_node);
 out_free_fpi:
 	kfree(fpi);
Acked-by on v1 1/2
#1 lore raw
Quoted 26 lines · Julia Lawall

In this case, a device_node structure is stored in another structure that is then freed without first decrementing the reference count of the device_node structure.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
expression x;
identifier f;
position p1,p2;
@@

x@p1->f = \(of_find_node_by_path\|of_find_node_by_name\|of_find_node_by_phandle\|of_get_parent\|of_get_next_parent\|of_get_next_child\|of_find_compatible_node\|of_match_node\|of_find_node_by_type\|of_find_node_with_property\|of_find_matching_node\|of_parse_phandle\|of_node_get\)(...); ... when != of_node_put(x)
kfree@p2(x)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@
cocci.print_main("call",p1)
cocci.print_secs("free",p2)
// </smpl>

Quoted 1 line
Quoted 31 lines
---
 drivers/net/fs_enet/fs_enet-main.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/fs_enet/fs_enet-main.c +2 -1
index d6e3111..d684f18 100644
@@ -1036,7 +1036,7 @@ static int __devinit fs_enet_probe(struct platform_device *ofdev,
 	ndev = alloc_etherdev(privsize);
 	if (!ndev) {
 		ret = -ENOMEM;
-		goto out_free_fpi;
+		goto out_put;
 	}
 
 	SET_NETDEV_DEV(ndev, &ofdev->dev);
@@ -1099,6 +1099,7 @@ out_cleanup_data:
 out_free_dev:
 	free_netdev(ndev);
 	dev_set_drvdata(&ofdev->dev, NULL);
+out_put:
 	of_node_put(fpi->phy_node);
 out_free_fpi:
 	kfree(fpi);

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
maintainer Applied
#2 lore raw
In reply to Julia Lawall

From: Julia Lawall <[email protected]>
Date: Sat, 4 Sep 2010 12:12:43 +0200

Quoted 6 lines

In this case, a device_node structure is stored in another structure that is then freed without first decrementing the reference count of the device_node structure.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

...

Quoted 1 line

Applied.