diff mbox series

[net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe

Message ID 20230403090321.835877-1-s-vadapalli@ti.com (mailing list archive)
State Accepted
Commit c6b486fb33680ad5a3a6390ce693c835caaae3f7
Delegated to: Netdev Maintainers
Headers show
Series [net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers fail 1 blamed authors not CCed: grygorii.strashko@ti.com; 1 maintainers not CCed: grygorii.strashko@ti.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Siddharth Vadapalli April 3, 2023, 9:03 a.m. UTC
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: a45cfcc69a25 ("net: ethernet: ti: am65-cpsw-nuss: use of_platform_device_create() for mdio")
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Roger Quadros April 3, 2023, 10:49 a.m. UTC | #1
On 03/04/2023 12:03, Siddharth Vadapalli wrote:
> 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: a45cfcc69a25 ("net: ethernet: ti: am65-cpsw-nuss: use of_platform_device_create() for mdio")
> Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>

Reviewed-by: Roger Quadros <rogerq@kernel.org>
patchwork-bot+netdevbpf@kernel.org April 4, 2023, 10:40 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 3 Apr 2023 14:33:21 +0530 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe
    https://git.kernel.org/netdev/net/c/c6b486fb3368

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 4e3861c47708..bcea87b7151c 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -2926,7 +2926,8 @@  static int am65_cpsw_nuss_probe(struct platform_device *pdev)
 	am65_cpsw_nuss_phylink_cleanup(common);
 	am65_cpts_release(common->cpts);
 err_of_clear:
-	of_platform_device_destroy(common->mdio_dev, NULL);
+	if (common->mdio_dev)
+		of_platform_device_destroy(common->mdio_dev, NULL);
 err_pm_clear:
 	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
@@ -2956,7 +2957,8 @@  static int am65_cpsw_nuss_remove(struct platform_device *pdev)
 	am65_cpts_release(common->cpts);
 	am65_cpsw_disable_serdes_phy(common);
 
-	of_platform_device_destroy(common->mdio_dev, NULL);
+	if (common->mdio_dev)
+		of_platform_device_destroy(common->mdio_dev, NULL);
 
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);