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

net: phy: abort loading yt8511 driver in unsupported modes

While investigating the clang `ge` uninitialized variable report, it was
discovered the default switch would have unintended consequences. Due to
the switch to __phy_modify, the driver would modify the ID values in the
default scenario.

Fix this by promoting the interface mode switch and aborting when the
mode is not a supported RGMII mode.

This prevents the `ge` and `fe` variables from ever being used
uninitialized.

Fixes: 48e8c6f1612b ("net: phy: add driver for Motorcomm yt8511 phy")
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Peter Geis <pgwipeout@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Peter Geis and committed by
Jakub Kicinski
0cc8bddb 546d6bad

+8 -7
+8 -7
drivers/net/phy/motorcomm.c
··· 53 53 int oldpage, ret = 0; 54 54 unsigned int ge, fe; 55 55 56 - /* set clock mode to 125mhz */ 57 56 oldpage = phy_select_page(phydev, YT8511_EXT_CLK_GATE); 58 57 if (oldpage < 0) 59 - goto err_restore_page; 60 - 61 - ret = __phy_modify(phydev, YT8511_PAGE, 0, YT8511_CLK_125M); 62 - if (ret < 0) 63 58 goto err_restore_page; 64 59 65 60 /* set rgmii delay mode */ ··· 75 80 ge = YT8511_DELAY_RX | YT8511_DELAY_GE_TX_EN; 76 81 fe = YT8511_DELAY_FE_TX_EN; 77 82 break; 78 - default: /* leave everything alone in other modes */ 79 - break; 83 + default: /* do not support other modes */ 84 + ret = -EOPNOTSUPP; 85 + goto err_restore_page; 80 86 } 81 87 82 88 ret = __phy_modify(phydev, YT8511_PAGE, (YT8511_DELAY_RX | YT8511_DELAY_GE_TX_EN), ge); 89 + if (ret < 0) 90 + goto err_restore_page; 91 + 92 + /* set clock mode to 125mhz */ 93 + ret = __phy_modify(phydev, YT8511_PAGE, 0, YT8511_CLK_125M); 83 94 if (ret < 0) 84 95 goto err_restore_page; 85 96