summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Hu <huhai@kylinos.cn>2026-09-03 19:30:46 +0800
committerJakub Kicinski <kuba@kernel.org>2026-09-07 17:20:19 -0700
commita4050ce7e46cecbc25eadfa89e4b907b1906a4f9 (patch)
tree8d52950305d03ae55f6afa4c245ba5a18b3ac636
parent6f157f39d1812ac5efd113a29bff3799dcb3150c (diff)
downloadlinux-next-a4050ce7e46cecbc25eadfa89e4b907b1906a4f9.tar.gz
linux-next-a4050ce7e46cecbc25eadfa89e4b907b1906a4f9.zip
net: phy: microchip_t1: fix NULL pointer dereference in lan887x_phy_init()
The issue was discovered via smatch static analyzer: make CHECK="smatch -p=kernel" C=2 drivers/net/phy/microchip_t1.o CHECK scripts/mod/empty.c DESCEND objtool CHECK drivers/net/phy/microchip_t1.c drivers/net/phy/microchip_t1.c:1295 lan887x_phy_init() warn: 'priv->clock' can also be NULL mchp_rds_ptp_probe() returns NULL when CONFIG_MICROCHIP_PHY_RDS_PTP or CONFIG_PTP_1588_CLOCK is disabled. However, lan887x_phy_init() only checks for an error pointer before using the returned clock to configure the periodic output pin, which can result in a NULL pointer dereference. Handle the NULL return as PTP being unavailable and skip the event pin configuration in that case. Smatch no longer reports the NULL dereference warning after the change. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Reviewed-by: Divya Koppera <Divya.Koppera@microchip.com> Signed-off-by: Henry Hu <huhai@kylinos.cn> Link: https://patch.msgid.link/20260903113046.163630-1-15815827059@163.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--drivers/net/phy/microchip_t1.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
index 3292b2235c8f..e38d20bf6aa4 100644
--- a/drivers/net/phy/microchip_t1.c
+++ b/drivers/net/phy/microchip_t1.c
@@ -1285,14 +1285,16 @@ static int lan887x_phy_init(struct phy_device *phydev)
if (IS_ERR(priv->clock))
return PTR_ERR(priv->clock);
- /* Enable pin mux for EVT */
- phy_modify_mmd(phydev, MDIO_MMD_VEND1,
- LAN887X_MX_CHIP_TOP_REG_CONTROL1,
- LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN,
- LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN);
-
- /* Initialize pin numbers specific to PEROUT */
- priv->clock->event_pin = 3;
+ if (priv->clock) {
+ /* Enable pin mux for EVT */
+ phy_modify_mmd(phydev, MDIO_MMD_VEND1,
+ LAN887X_MX_CHIP_TOP_REG_CONTROL1,
+ LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN,
+ LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN);
+
+ /* Initialize pin numbers specific to PEROUT */
+ priv->clock->event_pin = 3;
+ }
priv->init_done = true;
}