phylink: avoid attaching more than one PHY
authorRussell King <rmk+kernel@armlinux.org.uk>
Wed, 20 Dec 2017 23:23:33 +0000 (23:23 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Dec 2017 20:03:10 +0000 (15:03 -0500)
Attaching more than one PHY to phylink is bad news, as we store a
pointer to the PHY in a single location. Error out if more than one
PHY is attempted to be attached.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phylink.c

index f7a77747576247d993da18762b09461673854a16..2ec140ec79237326a1aac44f7ae56fcc031f5fea 100644 (file)
@@ -725,6 +725,9 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
                     phy_interface_mode_is_8023z(pl->link_interface))))
                return -EINVAL;
 
+       if (pl->phydev)
+               return -EBUSY;
+
        /* Use PHY device/driver interface */
        if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
                pl->link_interface = phy->interface;