Commit 9404c82b authored by Grant Likely's avatar Grant Likely Committed by David S. Miller

net/fec_mpc52xx: Don't dereference phy_device if it is NULL

The FEC Ethernet device isn't always attached to a phy.  Be careful
not to dereference phy_device if it is NULL.  Also eliminates an
unnecessary extra function from the ioctl path.
Reported-by: default avatarHenk Stegeman <henk.stegeman@gmail.com>
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d360009c
...@@ -271,15 +271,6 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev) ...@@ -271,15 +271,6 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev)
phy_write(priv->phydev, MII_BMCR, BMCR_PDOWN); phy_write(priv->phydev, MII_BMCR, BMCR_PDOWN);
} }
static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv,
struct mii_ioctl_data *mii_data, int cmd)
{
if (!priv->phydev)
return -ENOTSUPP;
return phy_mii_ioctl(priv->phydev, mii_data, cmd);
}
static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv) static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv)
{ {
struct mpc52xx_fec __iomem *fec = priv->fec; struct mpc52xx_fec __iomem *fec = priv->fec;
...@@ -852,12 +843,20 @@ static void mpc52xx_fec_get_drvinfo(struct net_device *dev, ...@@ -852,12 +843,20 @@ static void mpc52xx_fec_get_drvinfo(struct net_device *dev,
static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
{ {
struct mpc52xx_fec_priv *priv = netdev_priv(dev); struct mpc52xx_fec_priv *priv = netdev_priv(dev);
if (!priv->phydev)
return -ENODEV;
return phy_ethtool_gset(priv->phydev, cmd); return phy_ethtool_gset(priv->phydev, cmd);
} }
static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
{ {
struct mpc52xx_fec_priv *priv = netdev_priv(dev); struct mpc52xx_fec_priv *priv = netdev_priv(dev);
if (!priv->phydev)
return -ENODEV;
return phy_ethtool_sset(priv->phydev, cmd); return phy_ethtool_sset(priv->phydev, cmd);
} }
...@@ -887,7 +886,10 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ...@@ -887,7 +886,10 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{ {
struct mpc52xx_fec_priv *priv = netdev_priv(dev); struct mpc52xx_fec_priv *priv = netdev_priv(dev);
return mpc52xx_fec_phy_mii_ioctl(priv, if_mii(rq), cmd); if (!priv->phydev)
return -ENOTSUPP;
return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
} }
static const struct net_device_ops mpc52xx_fec_netdev_ops = { static const struct net_device_ops mpc52xx_fec_netdev_ops = {
......
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