Skip to content

Commit b31c7e7

Browse files
rgantoisPaolo Abeni
authored andcommitted
net: ti: icssg_prueth: Fix NULL pointer dereference in prueth_probe()
In the prueth_probe() function, if one of the calls to emac_phy_connect() fails due to of_phy_connect() returning NULL, then the subsequent call to phy_attached_info() will dereference a NULL pointer. Check the return code of emac_phy_connect and fail cleanly if there is an error. Fixes: 128d587 ("net: ti: icssg-prueth: Add ICSSG ethernet driver") Cc: stable@vger.kernel.org Signed-off-by: Romain Gantois <romain.gantois@bootlin.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: MD Danish Anwar <danishanwar@ti.com> Link: https://lore.kernel.org/r/20240521-icssg-prueth-fix-v1-1-b4b17b1433e9@bootlin.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 91e61dd commit b31c7e7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,12 @@ static int prueth_probe(struct platform_device *pdev)
10391039

10401040
prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev;
10411041

1042-
emac_phy_connect(prueth->emac[PRUETH_MAC0]);
1042+
ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]);
1043+
if (ret) {
1044+
dev_err(dev,
1045+
"can't connect to MII0 PHY, error -%d", ret);
1046+
goto netdev_unregister;
1047+
}
10431048
phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev);
10441049
}
10451050

@@ -1051,7 +1056,12 @@ static int prueth_probe(struct platform_device *pdev)
10511056
}
10521057

10531058
prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev;
1054-
emac_phy_connect(prueth->emac[PRUETH_MAC1]);
1059+
ret = emac_phy_connect(prueth->emac[PRUETH_MAC1]);
1060+
if (ret) {
1061+
dev_err(dev,
1062+
"can't connect to MII1 PHY, error %d", ret);
1063+
goto netdev_unregister;
1064+
}
10551065
phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev);
10561066
}
10571067

0 commit comments

Comments
 (0)