From patchwork Fri Sep 6 10:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Paukrt X-Patchwork-Id: 13793919 Received: from mxe.seznam.cz (mxe.seznam.cz [77.75.76.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45B4C149013 for ; Fri, 6 Sep 2024 10:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.75.76.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725620020; cv=none; b=YOlSTd8gAOjHlYV+q6FpQB70Qu91r5Ukjbec+LHVUNM+rYS5BHBBY55EcY1suL1ea90MMuSvdI9V8ayPU8zDvZiyi7O5eGROOMWymeAyqTR3T6DgQaPoksztWHkYiuuygPh9U5A4k1KMgPtDG6Z6wRMLOV1FYRtVIr5Y+2ac/vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725620020; c=relaxed/simple; bh=nCBQAauA2ILCBmP6CvuTWLmj6nXO7ZVYQUlsyc4Nn4I=; h=From:To:Cc:Subject:Date:Message-Id:Mime-Version:Content-Type; b=W0ICRrnAjCmyeWvaKjW3JdK40TEOPstisjqDkBnhxUpHqHl4dn43B5ARQlbhfMDBkIA573KKi4G4M76485zuUaRcqXunwRtvj/SSdXokvXI0MAiaXtwShtXeoTLEm3/MPktTxtZ22WuPxkgTxuf9AcbMEoTmRRYavtrgXBpgPv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=email.cz; spf=pass smtp.mailfrom=email.cz; dkim=pass (2048-bit key) header.d=email.cz header.i=@email.cz header.b=WsZt2791; arc=none smtp.client-ip=77.75.76.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=email.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=email.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=email.cz header.i=@email.cz header.b="WsZt2791" Received: from email.seznam.cz by smtpc-mxe-6f7b5db655-grmdl (smtpc-mxe-6f7b5db655-grmdl [2a02:598:128:8a00::1000:50f]) id 20c4a0bede301214204a2ea6; Fri, 06 Sep 2024 12:52:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=szn20221014; t=1725619964; bh=L9fSUq9wqsb6tjOKmQgNimpO8VBJXjzkjf6Vt4Q8Jro=; h=Received:From:To:Cc:Subject:Date:Message-Id:Mime-Version:X-Mailer: Content-Type:Content-Transfer-Encoding; b=WsZt2791To6yIoZN7ZJBI7JPg4gaWsXKqqA5HSA/kzu6RYOaiPrhiowgT3FIxk6U1 Nioqm/cEdlkUKBM0GMKHSHVDk0Np7wZKfwnorK7Q0OdGnxq3+95hU42xepu3Llwoml POKvPLAwLJe6U+8/lBqsC6Ka4Z/rWf2WyxVfAPCg51reNHiqcTIdtvfL3Bmk8ABRT2 mtbAfa5Nbo+7/DvccsU6qtbgc3+wffmKi7ZfHCTw4qunO+HQ5q4cKwHiWquV9LmOP+ lKie0F77Fqe6osJKNsk/JTJzmJ6ps48KZ4p60bXZ2yWpcAhKdTvoW5JWYPAPKMW3qJ n8BkZMJqw+Dwg== Received: from 215-143.ktuo.cz (215-143.ktuo.cz [82.144.143.215]) by email.seznam.cz (szn-UNKNOWN-unknown) with HTTP; Fri, 06 Sep 2024 12:52:40 +0200 (CEST) From: "Tomas Paukrt" To: Cc: "Andrew Lunn" , "Heiner Kallweit" , "Russell King" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Catalin Popescu" , "Simon Horman" Subject: =?utf-8?q?=5BPATCH_net_v2=5D_net=3A_phy=3A_dp83822=3A_Fix_NULL_poin?= =?utf-8?q?ter_dereference_on_DP83825_devices?= Date: Fri, 06 Sep 2024 12:52:40 +0200 (CEST) Message-Id: <66w.ZbGt.65Ljx42yHo5.1csjxu@seznam.cz> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (szn-mime-2.1.61) X-Mailer: szn-UNKNOWN-unknown The probe() function is only used for DP83822 and DP83826 PHY, leaving the private data pointer uninitialized for the DP83825 models which causes a NULL pointer dereference in the recently introduced/changed functions dp8382x_config_init() and dp83822_set_wol(). Add the dp8382x_probe() function, so all PHY models will have a valid private data pointer to fix this issue and also prevent similar issues in the future. Fixes: 9ef9ecfa9e9f ("net: phy: dp8382x: keep WOL settings across suspends") Signed-off-by: Tomas Paukrt Reviewed-by: Maxime Chevallier --- Changes since v1: - Reused the newly introduced function in dp83822_probe() and dp83826_probe() --- drivers/net/phy/dp83822.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c index efeb643..fc247f4 100644 --- a/drivers/net/phy/dp83822.c +++ b/drivers/net/phy/dp83822.c @@ -271,8 +271,7 @@ static int dp83822_config_intr(struct phy_device *phydev) DP83822_ENERGY_DET_INT_EN | DP83822_LINK_QUAL_INT_EN); - /* Private data pointer is NULL on DP83825 */ - if (!dp83822 || !dp83822->fx_enabled) + if (!dp83822->fx_enabled) misr_status |= DP83822_ANEG_COMPLETE_INT_EN | DP83822_DUP_MODE_CHANGE_INT_EN | DP83822_SPEED_CHANGED_INT_EN; @@ -292,8 +291,7 @@ static int dp83822_config_intr(struct phy_device *phydev) DP83822_PAGE_RX_INT_EN | DP83822_EEE_ERROR_CHANGE_INT_EN); - /* Private data pointer is NULL on DP83825 */ - if (!dp83822 || !dp83822->fx_enabled) + if (!dp83822->fx_enabled) misr_status |= DP83822_ANEG_ERR_INT_EN | DP83822_WOL_PKT_INT_EN; @@ -691,10 +689,9 @@ static int dp83822_read_straps(struct phy_device *phydev) return 0; } -static int dp83822_probe(struct phy_device *phydev) +static int dp8382x_probe(struct phy_device *phydev) { struct dp83822_private *dp83822; - int ret; dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822), GFP_KERNEL); @@ -703,6 +700,20 @@ static int dp83822_probe(struct phy_device *phydev) phydev->priv = dp83822; + return 0; +} + +static int dp83822_probe(struct phy_device *phydev) +{ + struct dp83822_private *dp83822; + int ret; + + ret = dp8382x_probe(phydev); + if (ret) + return ret; + + dp83822 = phydev->priv; + ret = dp83822_read_straps(phydev); if (ret) return ret; @@ -717,14 +728,11 @@ static int dp83822_probe(struct phy_device *phydev) static int dp83826_probe(struct phy_device *phydev) { - struct dp83822_private *dp83822; - - dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822), - GFP_KERNEL); - if (!dp83822) - return -ENOMEM; + int ret; - phydev->priv = dp83822; + ret = dp8382x_probe(phydev); + if (ret) + return ret; dp83826_of_init(phydev); @@ -795,6 +803,7 @@ static int dp83822_resume(struct phy_device *phydev) PHY_ID_MATCH_MODEL(_id), \ .name = (_name), \ /* PHY_BASIC_FEATURES */ \ + .probe = dp8382x_probe, \ .soft_reset = dp83822_phy_reset, \ .config_init = dp8382x_config_init, \ .get_wol = dp83822_get_wol, \