Skip to content

Commit

Permalink
Merge branch 'phy-ref-leaks'
Browse files Browse the repository at this point in the history
Johan Hovold says:

====================
net: fix device reference leaks

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
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 7, 2016
2 parents 6a0c9f6 + 2271150 commit ee0475a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion drivers/net/ethernet/hisilicon/hns/hnae.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
return ERR_PTR(-ENODEV);

handle = dev->ops->get_handle(dev, port_id);
if (IS_ERR(handle))
if (IS_ERR(handle)) {
put_device(&dev->cls_dev);
return handle;
}

handle->dev = dev;
handle->owner_dev = owner_dev;
Expand All @@ -356,6 +358,8 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
for (j = i - 1; j >= 0; j--)
hnae_fini_queue(handle->qs[j]);

put_device(&dev->cls_dev);

return ERR_PTR(-ENOMEM);
}
EXPORT_SYMBOL(hnae_get_handle);
Expand All @@ -377,6 +381,8 @@ void hnae_put_handle(struct hnae_handle *h)
dev->ops->put_handle(h);

module_put(dev->owner);

put_device(&dev->cls_dev);
}
EXPORT_SYMBOL(hnae_put_handle);

Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/ti/cpsw-phy-sel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions drivers/net/ethernet/ti/davinci_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/phy/phy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ee0475a

Please sign in to comment.