aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2015-09-24 20:36:33 +0100
committerDavid S. Miller <davem@davemloft.net>2015-09-24 23:04:53 -0700
commit9861f72074c77a8a065622c1be7e9c4277e600eb (patch)
treecba58d3959606f2f4d7dd5ea95f8a79ac73fd2ad /net/dsa
parentphy: add phy_device_remove() (diff)
downloadlinux-dev-9861f72074c77a8a065622c1be7e9c4277e600eb.tar.xz
linux-dev-9861f72074c77a8a065622c1be7e9c4277e600eb.zip
net: fix net_device refcounting
of_find_net_device_by_node() uses class_find_device() internally to lookup the corresponding network device. class_find_device() returns a reference to the embedded struct device, with its refcount incremented. Add a comment to the definition in net/core/net-sysfs.c indicating the need to drop this refcount, and fix the DSA code to drop this refcount when the OF-generated platform data is cleaned up and freed. Also arrange for the ref to be dropped when handling errors. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r--net/dsa/dsa.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index bf4ba15fb780..c59fa5d9c22c 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -679,7 +679,7 @@ static int dsa_of_probe(struct device *dev)
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (!pd) {
ret = -ENOMEM;
- goto out_put_mdio;
+ goto out_put_ethernet;
}
dev->platform_data = pd;
@@ -773,6 +773,8 @@ out_free_chip:
out_free:
kfree(pd);
dev->platform_data = NULL;
+out_put_ethernet:
+ put_device(&ethernet_dev->dev);
out_put_mdio:
put_device(&mdio_bus->dev);
return ret;
@@ -786,6 +788,7 @@ static void dsa_of_remove(struct device *dev)
return;
dsa_of_free_platform_data(pd);
+ put_device(&pd->of_netdev->dev);
kfree(pd);
}
#else