Netdev List
 help / color / mirror / Atom feed
From: huhai <15815827059@163.com>
To: kuba@kernel.org, andrew@lunn.ch, divya.koppera@microchip.com
Cc: netdev@vger.kernel.org, huhai <huhai@kylinos.cn>
Subject: [PATCH] net: phy: microchip_t1: fix NULL pointer dereference in lan887x_phy_init()
Date: Wed,  2 Sep 2026 16:33:42 +0800	[thread overview]
Message-ID: <20260902083342.221050-1-15815827059@163.com> (raw)

From: huhai <huhai@kylinos.cn>

mchp_rds_ptp_probe() may return NULL when CONFIG_PTP_1588_CLOCK is disabled.
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.

Fixes: 8541fc12edcd ("net: phy: microchip_t1: Enable pin out specific to lan887x phy for PEROUT signal")
Signed-off-by: huhai <huhai@kylinos.cn>
---
 drivers/net/phy/microchip_t1.c | 18 ++++++++++--------
 1 file 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;
 	}
-- 
2.40.1


             reply	other threads:[~2026-09-02  8:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  8:33 huhai [this message]
2026-09-02  8:56 ` [PATCH] net: phy: microchip_t1: fix NULL pointer dereference in lan887x_phy_init() Divya.Koppera
2026-09-02  9:16 ` Xuanqiang Luo
2026-09-02 22:58   ` Jakub Kicinski
2026-09-03  9:01     ` huhai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902083342.221050-1-15815827059@163.com \
    --to=15815827059@163.com \
    --cc=andrew@lunn.ch \
    --cc=divya.koppera@microchip.com \
    --cc=huhai@kylinos.cn \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox