]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
net:stmmac: Add check if mdiobus is registered in stmmac_mdio_unregister
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>
Thu, 30 Aug 2012 05:49:58 +0000 (05:49 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 31 Aug 2012 20:11:16 +0000 (16:11 -0400)
This patch adds a basic check in stmmac_mdio_unregister to see if mdio
bus registeration for this driver was actually sucessfull or not.

Use case here is, if BSP considers using mdio-gpio bus along with stmmac
driver by passing mdio_bus_data as NULL in platform data.
Call to stmmac_mdio_register with mdio_bus_data as NULL returns 0, which
is a considered sucessfull call form stmmac. Then again when we unload
the driver we just call stmmac_mdio_unregister, this is were the actual
problem is stmmac-mdio code dont really know at this instance of calling
that stmmac_mdio_register was actually successful.

So Adding a check in stmmac_mdio_unregister is always safe.

Without this patch stmmac driver calls stmmac_mdio_register from
stmmac_release which Segfaults as mii bus was never registered at the
first point.

Originally the this bug was found when unloading an stmmac driver
instance which uses mdio-gpio for smi access.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

index ade108232048aca7771e2a3d0ea9d6d5a15f7a45..e1f3d04a8c90113790fb2efd8894d898e9b65b37 100644 (file)
@@ -258,6 +258,9 @@ int stmmac_mdio_unregister(struct net_device *ndev)
 {
        struct stmmac_priv *priv = netdev_priv(ndev);
 
+       if (!priv->mii)
+               return 0;
+
        mdiobus_unregister(priv->mii);
        priv->mii->priv = NULL;
        mdiobus_free(priv->mii);