Skip to content

Commit

Permalink
Merge branch 'dsa'
Browse files Browse the repository at this point in the history
Florian Fainelli says:

====================
net: dsa: two small bug fixes

Here are two small fixes for the DSA slave interface creation code:

- first patch fixes a null pointer de-reference with an invalid PHY
  device pointer while calling phy_connect_direct()

- second path propagates the dsa_slave_phy_setup() error code down to
  its caller: dsa_slave_create
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Dec 12, 2014
2 parents 70e71ca + 9697f1c commit c11a900
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static int dsa_slave_fixed_link_update(struct net_device *dev,
}

/* slave device setup *******************************************************/
static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
struct net_device *slave_dev)
{
struct dsa_switch *ds = p->parent;
Expand All @@ -533,7 +533,7 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
ret = of_phy_register_fixed_link(port_dn);
if (ret) {
netdev_err(slave_dev, "failed to register fixed PHY\n");
return;
return ret;
}
phy_is_fixed = true;
phy_dn = port_dn;
Expand All @@ -555,12 +555,17 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
*/
if (!p->phy) {
p->phy = ds->slave_mii_bus->phy_map[p->port];
if (!p->phy)
return -ENODEV;

phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
p->phy_interface);
} else {
netdev_info(slave_dev, "attached PHY at address %d [%s]\n",
p->phy->addr, p->phy->drv->name);
}

return 0;
}

int dsa_slave_suspend(struct net_device *slave_dev)
Expand Down Expand Up @@ -653,12 +658,17 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
p->old_link = -1;
p->old_duplex = -1;

dsa_slave_phy_setup(p, slave_dev);
ret = dsa_slave_phy_setup(p, slave_dev);
if (ret) {
free_netdev(slave_dev);
return NULL;
}

ret = register_netdev(slave_dev);
if (ret) {
netdev_err(master, "error %d registering interface %s\n",
ret, slave_dev->name);
phy_disconnect(p->phy);
free_netdev(slave_dev);
return NULL;
}
Expand Down

0 comments on commit c11a900

Please sign in to comment.