Skip to content

Commit c6b486f

Browse files
Siddharth-Vadapalli-at-TIPaolo Abeni
authored andcommitted
net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe
In the am65_cpsw_nuss_probe() function's cleanup path, the call to of_platform_device_destroy() for the common->mdio_dev device is invoked unconditionally. It is possible that either the MDIO node is not present in the device-tree, or the MDIO node is disabled in the device-tree. In both these cases, the MDIO device is not created, resulting in a NULL pointer dereference when the of_platform_device_destroy() function is invoked on the common->mdio_dev device on the cleanup path. Fix this by ensuring that the common->mdio_dev device exists, before attempting to invoke of_platform_device_destroy(). Fixes: a45cfcc ("net: ethernet: ti: am65-cpsw-nuss: use of_platform_device_create() for mdio") Signed-off-by: Siddharth Vadapalli <[email protected]> Reviewed-by: Roger Quadros <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent ea30388 commit c6b486f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,8 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
29262926
am65_cpsw_nuss_phylink_cleanup(common);
29272927
am65_cpts_release(common->cpts);
29282928
err_of_clear:
2929-
of_platform_device_destroy(common->mdio_dev, NULL);
2929+
if (common->mdio_dev)
2930+
of_platform_device_destroy(common->mdio_dev, NULL);
29302931
err_pm_clear:
29312932
pm_runtime_put_sync(dev);
29322933
pm_runtime_disable(dev);
@@ -2956,7 +2957,8 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)
29562957
am65_cpts_release(common->cpts);
29572958
am65_cpsw_disable_serdes_phy(common);
29582959

2959-
of_platform_device_destroy(common->mdio_dev, NULL);
2960+
if (common->mdio_dev)
2961+
of_platform_device_destroy(common->mdio_dev, NULL);
29602962

29612963
pm_runtime_put_sync(&pdev->dev);
29622964
pm_runtime_disable(&pdev->dev);

0 commit comments

Comments
 (0)