Commit 6c53b1b1 authored by Steve Glendinning's avatar Steve Glendinning Committed by David S. Miller

smsc9420: prevent BUG() if ethtool is called with interface down

This patch fixes a null pointer dereference BUG() if ethtool is used on
an smsc9420 interface while it is down, because the phy_dev is only
allocated while the interface is up.
Signed-off-by: default avatarSteve Glendinning <steve.glendinning@smsc.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cc098dc7
...@@ -252,6 +252,9 @@ static int smsc9420_ethtool_get_settings(struct net_device *dev, ...@@ -252,6 +252,9 @@ static int smsc9420_ethtool_get_settings(struct net_device *dev,
{ {
struct smsc9420_pdata *pd = netdev_priv(dev); struct smsc9420_pdata *pd = netdev_priv(dev);
if (!pd->phy_dev)
return -ENODEV;
cmd->maxtxpkt = 1; cmd->maxtxpkt = 1;
cmd->maxrxpkt = 1; cmd->maxrxpkt = 1;
return phy_ethtool_gset(pd->phy_dev, cmd); return phy_ethtool_gset(pd->phy_dev, cmd);
...@@ -262,6 +265,9 @@ static int smsc9420_ethtool_set_settings(struct net_device *dev, ...@@ -262,6 +265,9 @@ static int smsc9420_ethtool_set_settings(struct net_device *dev,
{ {
struct smsc9420_pdata *pd = netdev_priv(dev); struct smsc9420_pdata *pd = netdev_priv(dev);
if (!pd->phy_dev)
return -ENODEV;
return phy_ethtool_sset(pd->phy_dev, cmd); return phy_ethtool_sset(pd->phy_dev, cmd);
} }
...@@ -290,6 +296,10 @@ static void smsc9420_ethtool_set_msglevel(struct net_device *netdev, u32 data) ...@@ -290,6 +296,10 @@ static void smsc9420_ethtool_set_msglevel(struct net_device *netdev, u32 data)
static int smsc9420_ethtool_nway_reset(struct net_device *netdev) static int smsc9420_ethtool_nway_reset(struct net_device *netdev)
{ {
struct smsc9420_pdata *pd = netdev_priv(netdev); struct smsc9420_pdata *pd = netdev_priv(netdev);
if (!pd->phy_dev)
return -ENODEV;
return phy_start_aneg(pd->phy_dev); return phy_start_aneg(pd->phy_dev);
} }
...@@ -312,6 +322,10 @@ smsc9420_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs, ...@@ -312,6 +322,10 @@ smsc9420_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs,
for (i = 0; i < 0x100; i += (sizeof(u32))) for (i = 0; i < 0x100; i += (sizeof(u32)))
data[j++] = smsc9420_reg_read(pd, i); data[j++] = smsc9420_reg_read(pd, i);
// cannot read phy registers if the net device is down
if (!phy_dev)
return;
for (i = 0; i <= 31; i++) for (i = 0; i <= 31; i++)
data[j++] = smsc9420_mii_read(phy_dev->bus, phy_dev->addr, i); data[j++] = smsc9420_mii_read(phy_dev->bus, phy_dev->addr, i);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment