Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1230435

[PATCH 9/9] net: fix net_device refcounting

From Russell King <rmk+kernel@arm.linux.org.uk>
Newsgroups linux.kernel
Subject [PATCH 9/9] net: fix net_device refcounting
Date 2015-09-22 18:20 +0200
Message-ID <qbysq-219-35@gated-at.bofh.it> (permalink)
References <qbysp-219-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 net/core/net-sysfs.c | 9 +++++++++
 net/dsa/dsa.c        | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index b279077c3089..805a95a48107 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1481,6 +1481,15 @@ static int of_dev_node_match(struct device *dev, const void *data)
 	return ret == 0 ? dev->of_node == data : ret;
 }
 
+/*
+ * of_find_net_device_by_node - lookup the net device for the device node
+ * @np: OF device node
+ *
+ * Looks up the net_device structure corresponding with the device node.
+ * If successful, returns a pointer to the net_device with the embedded
+ * struct device refcount incremented by one, or NULL on failure. The
+ * refcount must be dropped when done with the net_device.
+ */
 struct net_device *of_find_net_device_by_node(struct device_node *np)
 {
 	struct device *dev;
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 @@ static int dsa_of_probe(struct device *dev)
 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
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/9] Phy, mdiobus, and netdev struct device fixes Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 8/9] phy: add phy_device_remove() Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 5/9] of_mdio: fix MDIO phy device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 6/9] net: fix phy refcounting in a bunch of drivers Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 9/9] net: fix net_device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 2/9] net: dsa: fix of_mdio_find_bus() device refcount leak Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 3/9] phy: fix mdiobus module safety Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  [PATCH 4/9] phy: add proper phy struct device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-22 18:20 +0200
  Re: [PATCH v2 0/9] Phy, mdiobus, and netdev struct device fixes David Miller <davem@davemloft.net> - 2015-09-24 01:30 +0200
    Re: [PATCH v2 0/9] Phy, mdiobus, and netdev struct device fixes Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-09-24 18:10 +0200
  [PATCH RESEND v3 2/9] net: dsa: fix of_mdio_find_bus() device  refcount leak Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 7/9] phy: fixed-phy: properly validate phy in  fixed_phy_update_state() Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 5/9] of_mdio: fix MDIO phy device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
    Re: [PATCH RESEND v3 5/9] of_mdio: fix MDIO phy device refcounting Rob Herring <robh@kernel.org> - 2015-09-25 00:30 +0200
  [PATCH RESEND v3 4/9] phy: add proper phy struct device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 8/9] phy: add phy_device_remove() Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 1/9] phy: fix of_mdio_find_bus() device refcount  leak Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 6/9] net: fix phy refcounting in a bunch of drivers Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 3/9] phy: fix mdiobus module safety Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:40 +0200
  [PATCH RESEND v3 9/9] net: fix net_device refcounting Russell King <rmk+kernel@arm.linux.org.uk> - 2015-09-24 21:50 +0200

csiph-web