Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: don't allow __set_phy_supported to add unsupported modes

Currently __set_phy_supported allows to add modes w/o checking whether
the PHY supports them. This is wrong, it should never add modes but
only remove modes we don't want to support.

The commit marked as fixed didn't do anything wrong, it just copied
existing functionality to the helper which is being fixed now.

Fixes: f3a6bd393c2c ("phylib: Add phy_set_max_speed helper")
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Heiner Kallweit and committed by
David S. Miller
d2a36971 35b827b6

+8 -11
+8 -11
drivers/net/phy/phy_device.c
··· 1880 1880 1881 1881 static int __set_phy_supported(struct phy_device *phydev, u32 max_speed) 1882 1882 { 1883 - phydev->supported &= ~(PHY_1000BT_FEATURES | PHY_100BT_FEATURES | 1884 - PHY_10BT_FEATURES); 1885 - 1886 1883 switch (max_speed) { 1887 - default: 1888 - return -ENOTSUPP; 1889 - case SPEED_1000: 1890 - phydev->supported |= PHY_1000BT_FEATURES; 1884 + case SPEED_10: 1885 + phydev->supported &= ~PHY_100BT_FEATURES; 1891 1886 /* fall through */ 1892 1887 case SPEED_100: 1893 - phydev->supported |= PHY_100BT_FEATURES; 1894 - /* fall through */ 1895 - case SPEED_10: 1896 - phydev->supported |= PHY_10BT_FEATURES; 1888 + phydev->supported &= ~PHY_1000BT_FEATURES; 1889 + break; 1890 + case SPEED_1000: 1891 + break; 1892 + default: 1893 + return -ENOTSUPP; 1897 1894 } 1898 1895 1899 1896 return 0;