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


Groups > linux.kernel > #1514737 > unrolled thread

[PATCH net v2 0/4] net: fix device reference leaks

Started byJohan Hovold <johan@kernel.org>
First post2016-11-03 18:50 +0100
Last post2016-11-07 19:20 +0100
Articles 7 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH net v2 0/4] net: fix device reference leaks Johan Hovold <johan@kernel.org> - 2016-11-03 18:50 +0100
    [PATCH net v2 3/4] net: ethernet: ti: davinci_emac: fix device reference leak Johan Hovold <johan@kernel.org> - 2016-11-03 18:50 +0100
    [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks Johan Hovold <johan@kernel.org> - 2016-11-03 18:50 +0100
      Re: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and  of_node leaks Grygorii Strashko <grygorii.strashko@ti.com> - 2016-11-09 00:20 +0100
        Re: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and  of_node leaks Johan Hovold <johan@kernel.org> - 2016-11-09 11:00 +0100
    [PATCH net v2 1/4] phy: fix device reference leaks Johan Hovold <johan@kernel.org> - 2016-11-03 18:50 +0100
    Re: [PATCH net v2 0/4] net: fix device reference leaks David Miller <davem@davemloft.net> - 2016-11-07 19:20 +0100

#1514737 — [PATCH net v2 0/4] net: fix device reference leaks

FromJohan Hovold <johan@kernel.org>
Date2016-11-03 18:50 +0100
Subject[PATCH net v2 0/4] net: fix device reference leaks
Message-ID<szujf-70x-7@gated-at.bofh.it>
This series fixes a number of device reference leaks (and one of_node
leak) due to failure to drop the references taken by bus_find_device()
and friends.

Note that the final two patches have been compile tested only.

Thanks,
Johan


v2
 - hold reference to cpsw-phy-sel device while accessing private data as
   requested by David. Also update the commit message. (patch 1/4)
 - add linux-omap on CC where appropriate


Johan Hovold (4):
  phy: fix device reference leaks
  net: ethernet: ti: cpsw: fix device and of_node leaks
  net: ethernet: ti: davinci_emac: fix device reference leak
  net: hns: fix device reference leaks

 drivers/net/ethernet/hisilicon/hns/hnae.c |  8 +++++++-
 drivers/net/ethernet/ti/cpsw-phy-sel.c    |  3 +++
 drivers/net/ethernet/ti/davinci_emac.c    | 10 ++++++----
 drivers/net/phy/phy_device.c              |  2 ++
 4 files changed, 18 insertions(+), 5 deletions(-)

-- 
2.7.3

[toc] | [next] | [standalone]


#1514738 — [PATCH net v2 3/4] net: ethernet: ti: davinci_emac: fix device reference leak

FromJohan Hovold <johan@kernel.org>
Date2016-11-03 18:50 +0100
Subject[PATCH net v2 3/4] net: ethernet: ti: davinci_emac: fix device reference leak
Message-ID<szujg-70x-27@gated-at.bofh.it>
In reply to#1514737
Make sure to drop the references taken by bus_find_device() before
returning from emac_dev_open().

Note that phy_connect still takes a reference to the phy device.

Fixes: 5d69e0076a72 ("net: davinci_emac: switch to new mdio")
Cc: Mugunthan V N <mugunthanvnm@ti.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: linux-omap@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/ti/davinci_emac.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 2fd94a5bc1f3..84fbe5714f8b 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1410,6 +1410,7 @@ static int emac_dev_open(struct net_device *ndev)
 	int i = 0;
 	struct emac_priv *priv = netdev_priv(ndev);
 	struct phy_device *phydev = NULL;
+	struct device *phy = NULL;
 
 	ret = pm_runtime_get_sync(&priv->pdev->dev);
 	if (ret < 0) {
@@ -1488,19 +1489,20 @@ static int emac_dev_open(struct net_device *ndev)
 
 	/* use the first phy on the bus if pdata did not give us a phy id */
 	if (!phydev && !priv->phy_id) {
-		struct device *phy;
-
 		phy = bus_find_device(&mdio_bus_type, NULL, NULL,
 				      match_first_device);
-		if (phy)
+		if (phy) {
 			priv->phy_id = dev_name(phy);
+			if (!priv->phy_id || !*priv->phy_id)
+				put_device(phy);
+		}
 	}
 
 	if (!phydev && priv->phy_id && *priv->phy_id) {
 		phydev = phy_connect(ndev, priv->phy_id,
 				     &emac_adjust_link,
 				     PHY_INTERFACE_MODE_MII);
-
+		put_device(phy);	/* reference taken by bus_find_device */
 		if (IS_ERR(phydev)) {
 			dev_err(emac_dev, "could not connect to phy %s\n",
 				priv->phy_id);
-- 
2.7.3

[toc] | [prev] | [next] | [standalone]


#1514743 — [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks

FromJohan Hovold <johan@kernel.org>
Date2016-11-03 18:50 +0100
Subject[PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks
Message-ID<szujg-70x-29@gated-at.bofh.it>
In reply to#1514737
Make sure to drop the references taken by of_get_child_by_name() and
bus_find_device() before returning from cpsw_phy_sel().

Note that holding a reference to the cpsw-phy-sel device does not
prevent the devres-managed private data from going away.

Fixes: 5892cd135e16 ("drivers: net: cpsw-phy-sel: Add new driver...")
Cc: Mugunthan V N <mugunthanvnm@ti.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: linux-omap@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/ti/cpsw-phy-sel.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
index 054a8dd23dae..ba1e45ff6aae 100644
--- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
+++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
@@ -176,9 +176,12 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)
 	}
 
 	dev = bus_find_device(&platform_bus_type, NULL, node, match);
+	of_node_put(node);
 	priv = dev_get_drvdata(dev);
 
 	priv->cpsw_phy_sel(priv, phy_mode, slave);
+
+	put_device(dev);
 }
 EXPORT_SYMBOL_GPL(cpsw_phy_sel);
 
-- 
2.7.3

[toc] | [prev] | [next] | [standalone]


#1517639 — Re: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks

FromGrygorii Strashko <grygorii.strashko@ti.com>
Date2016-11-09 00:20 +0100
SubjectRe: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks
Message-ID<sBnQm-7DS-5@gated-at.bofh.it>
In reply to#1514743

On 11/03/2016 12:40 PM, Johan Hovold wrote:
> Make sure to drop the references taken by of_get_child_by_name() and
> bus_find_device() before returning from cpsw_phy_sel().
>
> Note that holding a reference to the cpsw-phy-sel device does not
> prevent the devres-managed private data from going away.
>
> Fixes: 5892cd135e16 ("drivers: net: cpsw-phy-sel: Add new driver...")
> Cc: Mugunthan V N <mugunthanvnm@ti.com>
> Cc: Grygorii Strashko <grygorii.strashko@ti.com>
> Cc: linux-omap@vger.kernel.org
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---

Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

>  drivers/net/ethernet/ti/cpsw-phy-sel.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
> index 054a8dd23dae..ba1e45ff6aae 100644
> --- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
> +++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
> @@ -176,9 +176,12 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)
>  	}
>
>  	dev = bus_find_device(&platform_bus_type, NULL, node, match);
> +	of_node_put(node);
>  	priv = dev_get_drvdata(dev);
>
>  	priv->cpsw_phy_sel(priv, phy_mode, slave);
> +
> +	put_device(dev);
>  }
>  EXPORT_SYMBOL_GPL(cpsw_phy_sel);
>
>

-- 
regards,
-grygorii

[toc] | [prev] | [next] | [standalone]


#1517871 — Re: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks

FromJohan Hovold <johan@kernel.org>
Date2016-11-09 11:00 +0100
SubjectRe: [PATCH net v2 2/4] net: ethernet: ti: cpsw: fix device and of_node leaks
Message-ID<sBxPI-5yX-7@gated-at.bofh.it>
In reply to#1517639
On Tue, Nov 08, 2016 at 05:19:29PM -0600, Grygorii Strashko wrote:
> 
> 
> On 11/03/2016 12:40 PM, Johan Hovold wrote:
> > Make sure to drop the references taken by of_get_child_by_name() and
> > bus_find_device() before returning from cpsw_phy_sel().
> >
> > Note that holding a reference to the cpsw-phy-sel device does not
> > prevent the devres-managed private data from going away.
> >
> > Fixes: 5892cd135e16 ("drivers: net: cpsw-phy-sel: Add new driver...")
> > Cc: Mugunthan V N <mugunthanvnm@ti.com>
> > Cc: Grygorii Strashko <grygorii.strashko@ti.com>
> > Cc: linux-omap@vger.kernel.org
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> 
> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

Thanks for the review. Note that David has already applied these, though.

Johan

[toc] | [prev] | [next] | [standalone]


#1514746 — [PATCH net v2 1/4] phy: fix device reference leaks

FromJohan Hovold <johan@kernel.org>
Date2016-11-03 18:50 +0100
Subject[PATCH net v2 1/4] phy: fix device reference leaks
Message-ID<szujg-70x-37@gated-at.bofh.it>
In reply to#1514737
Make sure to drop the reference taken by bus_find_device_by_name()
before returning from phy_connect() and phy_attach().

Note that both function still take a reference to the phy device
through phy_attach_direct().

Fixes: e13934563db0 ("[PATCH] PHY Layer fixup")
Cc: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/phy/phy_device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index e977ba931878..1a4bf8acad78 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -723,6 +723,7 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
 	phydev = to_phy_device(d);
 
 	rc = phy_connect_direct(dev, phydev, handler, interface);
+	put_device(d);
 	if (rc)
 		return ERR_PTR(rc);
 
@@ -953,6 +954,7 @@ struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
 	phydev = to_phy_device(d);
 
 	rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface);
+	put_device(d);
 	if (rc)
 		return ERR_PTR(rc);
 
-- 
2.7.3

[toc] | [prev] | [next] | [standalone]


#1516415

FromDavid Miller <davem@davemloft.net>
Date2016-11-07 19:20 +0100
Message-ID<sAWGu-6RG-31@gated-at.bofh.it>
In reply to#1514737
From: Johan Hovold <johan@kernel.org>
Date: Thu,  3 Nov 2016 18:40:18 +0100

> This series fixes a number of device reference leaks (and one of_node
> leak) due to failure to drop the references taken by bus_find_device()
> and friends.
> 
> Note that the final two patches have been compile tested only.
 ...
> v2
>  - hold reference to cpsw-phy-sel device while accessing private data as
>    requested by David. Also update the commit message. (patch 1/4)
>  - add linux-omap on CC where appropriate

Series applied, thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web