Commit c6b486fb authored by Siddharth Vadapalli's avatar Siddharth Vadapalli Committed by Paolo Abeni

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: a45cfcc6 ("net: ethernet: ti: am65-cpsw-nuss: use of_platform_device_create() for mdio")
Signed-off-by: default avatarSiddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: default avatarRoger Quadros <rogerq@kernel.org>
Link: https://lore.kernel.org/r/20230403090321.835877-1-s-vadapalli@ti.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent ea30388b
...@@ -2926,6 +2926,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) ...@@ -2926,6 +2926,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
am65_cpsw_nuss_phylink_cleanup(common); am65_cpsw_nuss_phylink_cleanup(common);
am65_cpts_release(common->cpts); am65_cpts_release(common->cpts);
err_of_clear: err_of_clear:
if (common->mdio_dev)
of_platform_device_destroy(common->mdio_dev, NULL); of_platform_device_destroy(common->mdio_dev, NULL);
err_pm_clear: err_pm_clear:
pm_runtime_put_sync(dev); pm_runtime_put_sync(dev);
...@@ -2956,6 +2957,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev) ...@@ -2956,6 +2957,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)
am65_cpts_release(common->cpts); am65_cpts_release(common->cpts);
am65_cpsw_disable_serdes_phy(common); am65_cpsw_disable_serdes_phy(common);
if (common->mdio_dev)
of_platform_device_destroy(common->mdio_dev, NULL); of_platform_device_destroy(common->mdio_dev, NULL);
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment