Skip to content

Commit 3f62ea5

Browse files
tpaukrtkuba-moo
authored andcommitted
net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices
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: 9ef9ecf ("net: phy: dp8382x: keep WOL settings across suspends") Signed-off-by: Tomas Paukrt <[email protected]> Reviewed-by: Maxime Chevallier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 48aa361 commit 3f62ea5

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

drivers/net/phy/dp83822.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ static int dp83822_config_intr(struct phy_device *phydev)
271271
DP83822_ENERGY_DET_INT_EN |
272272
DP83822_LINK_QUAL_INT_EN);
273273

274-
/* Private data pointer is NULL on DP83825 */
275-
if (!dp83822 || !dp83822->fx_enabled)
274+
if (!dp83822->fx_enabled)
276275
misr_status |= DP83822_ANEG_COMPLETE_INT_EN |
277276
DP83822_DUP_MODE_CHANGE_INT_EN |
278277
DP83822_SPEED_CHANGED_INT_EN;
@@ -292,8 +291,7 @@ static int dp83822_config_intr(struct phy_device *phydev)
292291
DP83822_PAGE_RX_INT_EN |
293292
DP83822_EEE_ERROR_CHANGE_INT_EN);
294293

295-
/* Private data pointer is NULL on DP83825 */
296-
if (!dp83822 || !dp83822->fx_enabled)
294+
if (!dp83822->fx_enabled)
297295
misr_status |= DP83822_ANEG_ERR_INT_EN |
298296
DP83822_WOL_PKT_INT_EN;
299297

@@ -691,10 +689,9 @@ static int dp83822_read_straps(struct phy_device *phydev)
691689
return 0;
692690
}
693691

694-
static int dp83822_probe(struct phy_device *phydev)
692+
static int dp8382x_probe(struct phy_device *phydev)
695693
{
696694
struct dp83822_private *dp83822;
697-
int ret;
698695

699696
dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822),
700697
GFP_KERNEL);
@@ -703,6 +700,20 @@ static int dp83822_probe(struct phy_device *phydev)
703700

704701
phydev->priv = dp83822;
705702

703+
return 0;
704+
}
705+
706+
static int dp83822_probe(struct phy_device *phydev)
707+
{
708+
struct dp83822_private *dp83822;
709+
int ret;
710+
711+
ret = dp8382x_probe(phydev);
712+
if (ret)
713+
return ret;
714+
715+
dp83822 = phydev->priv;
716+
706717
ret = dp83822_read_straps(phydev);
707718
if (ret)
708719
return ret;
@@ -717,14 +728,11 @@ static int dp83822_probe(struct phy_device *phydev)
717728

718729
static int dp83826_probe(struct phy_device *phydev)
719730
{
720-
struct dp83822_private *dp83822;
721-
722-
dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822),
723-
GFP_KERNEL);
724-
if (!dp83822)
725-
return -ENOMEM;
731+
int ret;
726732

727-
phydev->priv = dp83822;
733+
ret = dp8382x_probe(phydev);
734+
if (ret)
735+
return ret;
728736

729737
dp83826_of_init(phydev);
730738

@@ -795,6 +803,7 @@ static int dp83822_resume(struct phy_device *phydev)
795803
PHY_ID_MATCH_MODEL(_id), \
796804
.name = (_name), \
797805
/* PHY_BASIC_FEATURES */ \
806+
.probe = dp8382x_probe, \
798807
.soft_reset = dp83822_phy_reset, \
799808
.config_init = dp8382x_config_init, \
800809
.get_wol = dp83822_get_wol, \

0 commit comments

Comments
 (0)