aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2015-09-24 15:36:33 -0400
committerDavid S. Miller <davem@davemloft.net>2015-09-25 02:04:53 -0400
commit9861f72074c77a8a065622c1be7e9c4277e600eb (patch)
treecba58d3959606f2f4d7dd5ea95f8a79ac73fd2ad /net/dsa
parent38737e490d4ea91660d3cec83ef88c4e6d360ae4 (diff)
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)
679 pd = kzalloc(sizeof(*pd), GFP_KERNEL); 679 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
680 if (!pd) { 680 if (!pd) {
681 ret = -ENOMEM; 681 ret = -ENOMEM;
682 goto out_put_mdio; 682 goto out_put_ethernet;
683 } 683 }
684 684
685 dev->platform_data = pd; 685 dev->platform_data = pd;
@@ -773,6 +773,8 @@ out_free_chip:
773out_free: 773out_free:
774 kfree(pd); 774 kfree(pd);
775 dev->platform_data = NULL; 775 dev->platform_data = NULL;
776out_put_ethernet:
777 put_device(&ethernet_dev->dev);
776out_put_mdio: 778out_put_mdio:
777 put_device(&mdio_bus->dev); 779 put_device(&mdio_bus->dev);
778 return ret; 780 return ret;
@@ -786,6 +788,7 @@ static void dsa_of_remove(struct device *dev)
786 return; 788 return;
787 789
788 dsa_of_free_platform_data(pd); 790 dsa_of_free_platform_data(pd);
791 put_device(&pd->of_netdev->dev);
789 kfree(pd); 792 kfree(pd);
790} 793}
791#else 794#else