netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe
@ 2023-04-03  9:03 Siddharth Vadapalli
  2023-04-03 10:49 ` Roger Quadros
  2023-04-04 10:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Siddharth Vadapalli @ 2023-04-03  9:03 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, rogerq
  Cc: netdev, linux-kernel, linux-arm-kernel, srk, s-vadapalli

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(-)

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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe
  2023-04-03  9:03 [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe Siddharth Vadapalli
@ 2023-04-03 10:49 ` Roger Quadros
  2023-04-04 10:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Roger Quadros @ 2023-04-03 10:49 UTC (permalink / raw)
  To: Siddharth Vadapalli, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, linux-arm-kernel, srk



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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe
  2023-04-03  9:03 [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe Siddharth Vadapalli
  2023-04-03 10:49 ` Roger Quadros
@ 2023-04-04 10:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-04 10:40 UTC (permalink / raw)
  To: Siddharth Vadapalli
  Cc: davem, edumazet, kuba, pabeni, rogerq, netdev, linux-kernel,
	linux-arm-kernel, srk

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-04 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03  9:03 [PATCH net] net: ethernet: ti: am65-cpsw: Fix mdio cleanup in probe Siddharth Vadapalli
2023-04-03 10:49 ` Roger Quadros
2023-04-04 10:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).