public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path
@ 2026-02-05  2:47 Kevin Hao
  2026-02-05  2:47 ` [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in " Kevin Hao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kevin Hao @ 2026-02-05  2:47 UTC (permalink / raw)
  To: netdev
  Cc: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Saeed Mahameed, Daniel Zahka, Lorenzo Bianconi,
	Alexander Sverdlin, Nicolas Dichtel, Murali Karicheri,
	Ilias Apalodimas, Grygorii Strashko, linux-omap, stable,
	Kevin Hao

These two patches address duplicate or unnecessary netdev unregistration
in the cpsw_probe() error handling path.

---
Cc: Siddharth Vadapalli <s-vadapalli@ti.com>
Cc: Roger Quadros <rogerq@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>
Cc: Daniel Zahka <daniel.zahka@gmail.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Cc: Murali Karicheri <m-karicheri2@ti.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: linux-omap@vger.kernel.org
Cc: stable@vger.kernel.org

---
Kevin Hao (2):
      net: cpsw_new: Fix unnecessary netdev unregistration in cpsw_probe() error path
      net: cpsw_new: Fix potential unregister of netdev that has not been registered yet

 drivers/net/ethernet/ti/cpsw_new.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
---
base-commit: 0f8a890c4524d6e4013ff225e70de2aed7e6d726
change-id: 20260202-cpsw-error-path-dd5bc72d6daa

Best regards,
-- 
Kevin Hao <haokexin@gmail.com>


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

* [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in cpsw_probe() error path
  2026-02-05  2:47 [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path Kevin Hao
@ 2026-02-05  2:47 ` Kevin Hao
  2026-02-05 19:03   ` Alexander Sverdlin
  2026-02-05  2:47 ` [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet Kevin Hao
  2026-02-06  3:10 ` [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Kevin Hao @ 2026-02-05  2:47 UTC (permalink / raw)
  To: netdev
  Cc: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Saeed Mahameed, Daniel Zahka, Lorenzo Bianconi,
	Alexander Sverdlin, Nicolas Dichtel, Murali Karicheri,
	Ilias Apalodimas, Grygorii Strashko, linux-omap, stable,
	Kevin Hao

The current error handling in cpsw_probe() has two issues:
- cpsw_unregister_ports() may be called before cpsw_register_ports() has
  been executed.

- cpsw_unregister_ports() is already invoked within cpsw_register_ports()
  in case of a register_netdev() failure, but the error path would call
  it again.

Fixes: ed3525eda4c4 ("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac")
Signed-off-by: Kevin Hao <haokexin@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/net/ethernet/ti/cpsw_new.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c
index 21af0a10626aaf0ce6ecb04837899801743f3894..b9fc31eb06134dae33427eaba06341c39eb4b41c 100644
--- a/drivers/net/ethernet/ti/cpsw_new.c
+++ b/drivers/net/ethernet/ti/cpsw_new.c
@@ -2003,7 +2003,7 @@ static int cpsw_probe(struct platform_device *pdev)
 	/* setup netdevs */
 	ret = cpsw_create_ports(cpsw);
 	if (ret)
-		goto clean_unregister_netdev;
+		goto clean_cpts;
 
 	/* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and
 	 * MISC IRQs which are always kept disabled with this driver so
@@ -2017,14 +2017,14 @@ static int cpsw_probe(struct platform_device *pdev)
 			       0, dev_name(dev), cpsw);
 	if (ret < 0) {
 		dev_err(dev, "error attaching irq (%d)\n", ret);
-		goto clean_unregister_netdev;
+		goto clean_cpts;
 	}
 
 	ret = devm_request_irq(dev, cpsw->irqs_table[1], cpsw_tx_interrupt,
 			       0, dev_name(dev), cpsw);
 	if (ret < 0) {
 		dev_err(dev, "error attaching irq (%d)\n", ret);
-		goto clean_unregister_netdev;
+		goto clean_cpts;
 	}
 
 	if (!cpsw->cpts)
@@ -2034,7 +2034,7 @@ static int cpsw_probe(struct platform_device *pdev)
 			       0, dev_name(&pdev->dev), cpsw);
 	if (ret < 0) {
 		dev_err(dev, "error attaching misc irq (%d)\n", ret);
-		goto clean_unregister_netdev;
+		goto clean_cpts;
 	}
 
 	/* Enable misc CPTS evnt_pend IRQ */
@@ -2043,7 +2043,7 @@ static int cpsw_probe(struct platform_device *pdev)
 skip_cpts:
 	ret = cpsw_register_notifiers(cpsw);
 	if (ret)
-		goto clean_unregister_netdev;
+		goto clean_cpts;
 
 	ret = cpsw_register_devlink(cpsw);
 	if (ret)
@@ -2065,8 +2065,6 @@ static int cpsw_probe(struct platform_device *pdev)
 
 clean_unregister_notifiers:
 	cpsw_unregister_notifiers(cpsw);
-clean_unregister_netdev:
-	cpsw_unregister_ports(cpsw);
 clean_cpts:
 	cpts_release(cpsw->cpts);
 	cpdma_ctlr_destroy(cpsw->dma);

-- 
2.52.0


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

* [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet
  2026-02-05  2:47 [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path Kevin Hao
  2026-02-05  2:47 ` [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in " Kevin Hao
@ 2026-02-05  2:47 ` Kevin Hao
  2026-02-05 19:03   ` Alexander Sverdlin
  2026-02-06  3:10 ` [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Kevin Hao @ 2026-02-05  2:47 UTC (permalink / raw)
  To: netdev
  Cc: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Saeed Mahameed, Daniel Zahka, Lorenzo Bianconi,
	Alexander Sverdlin, Nicolas Dichtel, Murali Karicheri,
	Ilias Apalodimas, Grygorii Strashko, linux-omap, stable,
	Kevin Hao

If an error occurs during register_netdev() for the first MAC in
cpsw_register_ports(), even though cpsw->slaves[0].ndev is set to NULL,
cpsw->slaves[1].ndev would remain unchanged. This could later cause
cpsw_unregister_ports() to attempt unregistering the second MAC.
To address this, add a check for ndev->reg_state before calling
unregister_netdev(). With this change, setting cpsw->slaves[i].ndev
to NULL becomes unnecessary and can be removed accordingly.

Fixes: ed3525eda4c4 ("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac")
Signed-off-by: Kevin Hao <haokexin@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/net/ethernet/ti/cpsw_new.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c
index b9fc31eb06134dae33427eaba06341c39eb4b41c..7f42f58a4b031fab4c93680c153383e8eeb8f7f8 100644
--- a/drivers/net/ethernet/ti/cpsw_new.c
+++ b/drivers/net/ethernet/ti/cpsw_new.c
@@ -1472,7 +1472,7 @@ static void cpsw_unregister_ports(struct cpsw_common *cpsw)
 
 	for (i = 0; i < cpsw->data.slaves; i++) {
 		ndev = cpsw->slaves[i].ndev;
-		if (!ndev)
+		if (!ndev || ndev->reg_state != NETREG_REGISTERED)
 			continue;
 
 		priv = netdev_priv(ndev);
@@ -1494,7 +1494,6 @@ static int cpsw_register_ports(struct cpsw_common *cpsw)
 		if (ret) {
 			dev_err(cpsw->dev,
 				"cpsw: err registering net device%d\n", i);
-			cpsw->slaves[i].ndev = NULL;
 			break;
 		}
 	}

-- 
2.52.0


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

* Re: [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in cpsw_probe() error path
  2026-02-05  2:47 ` [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in " Kevin Hao
@ 2026-02-05 19:03   ` Alexander Sverdlin
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Sverdlin @ 2026-02-05 19:03 UTC (permalink / raw)
  To: Kevin Hao, netdev
  Cc: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Saeed Mahameed, Daniel Zahka, Lorenzo Bianconi, Nicolas Dichtel,
	Murali Karicheri, Ilias Apalodimas, Grygorii Strashko, linux-omap,
	stable

On Thu, 2026-02-05 at 10:47 +0800, Kevin Hao wrote:
> The current error handling in cpsw_probe() has two issues:
> - cpsw_unregister_ports() may be called before cpsw_register_ports() has
>   been executed.
> 
> - cpsw_unregister_ports() is already invoked within cpsw_register_ports()
>   in case of a register_netdev() failure, but the error path would call
>   it again.
> 
> Fixes: ed3525eda4c4 ("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac")
> Signed-off-by: Kevin Hao <haokexin@gmail.com>

Reviewed-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>

> Cc: stable@vger.kernel.org
> ---
>  drivers/net/ethernet/ti/cpsw_new.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c
> index 21af0a10626aaf0ce6ecb04837899801743f3894..b9fc31eb06134dae33427eaba06341c39eb4b41c 100644
> --- a/drivers/net/ethernet/ti/cpsw_new.c
> +++ b/drivers/net/ethernet/ti/cpsw_new.c
> @@ -2003,7 +2003,7 @@ static int cpsw_probe(struct platform_device *pdev)
>  	/* setup netdevs */
>  	ret = cpsw_create_ports(cpsw);
>  	if (ret)
> -		goto clean_unregister_netdev;
> +		goto clean_cpts;
>  
>  	/* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and
>  	 * MISC IRQs which are always kept disabled with this driver so
> @@ -2017,14 +2017,14 @@ static int cpsw_probe(struct platform_device *pdev)
>  			       0, dev_name(dev), cpsw);
>  	if (ret < 0) {
>  		dev_err(dev, "error attaching irq (%d)\n", ret);
> -		goto clean_unregister_netdev;
> +		goto clean_cpts;
>  	}
>  
>  	ret = devm_request_irq(dev, cpsw->irqs_table[1], cpsw_tx_interrupt,
>  			       0, dev_name(dev), cpsw);
>  	if (ret < 0) {
>  		dev_err(dev, "error attaching irq (%d)\n", ret);
> -		goto clean_unregister_netdev;
> +		goto clean_cpts;
>  	}
>  
>  	if (!cpsw->cpts)
> @@ -2034,7 +2034,7 @@ static int cpsw_probe(struct platform_device *pdev)
>  			       0, dev_name(&pdev->dev), cpsw);
>  	if (ret < 0) {
>  		dev_err(dev, "error attaching misc irq (%d)\n", ret);
> -		goto clean_unregister_netdev;
> +		goto clean_cpts;
>  	}
>  
>  	/* Enable misc CPTS evnt_pend IRQ */
> @@ -2043,7 +2043,7 @@ static int cpsw_probe(struct platform_device *pdev)
>  skip_cpts:
>  	ret = cpsw_register_notifiers(cpsw);
>  	if (ret)
> -		goto clean_unregister_netdev;
> +		goto clean_cpts;
>  
>  	ret = cpsw_register_devlink(cpsw);
>  	if (ret)
> @@ -2065,8 +2065,6 @@ static int cpsw_probe(struct platform_device *pdev)
>  
>  clean_unregister_notifiers:
>  	cpsw_unregister_notifiers(cpsw);
> -clean_unregister_netdev:
> -	cpsw_unregister_ports(cpsw);
>  clean_cpts:
>  	cpts_release(cpsw->cpts);
>  	cpdma_ctlr_destroy(cpsw->dma);

-- 
Alexander Sverdlin.

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

* Re: [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet
  2026-02-05  2:47 ` [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet Kevin Hao
@ 2026-02-05 19:03   ` Alexander Sverdlin
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Sverdlin @ 2026-02-05 19:03 UTC (permalink / raw)
  To: Kevin Hao, netdev
  Cc: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Saeed Mahameed, Daniel Zahka, Lorenzo Bianconi, Nicolas Dichtel,
	Murali Karicheri, Ilias Apalodimas, Grygorii Strashko, linux-omap,
	stable

On Thu, 2026-02-05 at 10:47 +0800, Kevin Hao wrote:
> If an error occurs during register_netdev() for the first MAC in
> cpsw_register_ports(), even though cpsw->slaves[0].ndev is set to NULL,
> cpsw->slaves[1].ndev would remain unchanged. This could later cause
> cpsw_unregister_ports() to attempt unregistering the second MAC.
> To address this, add a check for ndev->reg_state before calling
> unregister_netdev(). With this change, setting cpsw->slaves[i].ndev
> to NULL becomes unnecessary and can be removed accordingly.
> 
> Fixes: ed3525eda4c4 ("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac")
> Signed-off-by: Kevin Hao <haokexin@gmail.com>

Reviewed-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>

> Cc: stable@vger.kernel.org
> ---
>  drivers/net/ethernet/ti/cpsw_new.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c
> index b9fc31eb06134dae33427eaba06341c39eb4b41c..7f42f58a4b031fab4c93680c153383e8eeb8f7f8 100644
> --- a/drivers/net/ethernet/ti/cpsw_new.c
> +++ b/drivers/net/ethernet/ti/cpsw_new.c
> @@ -1472,7 +1472,7 @@ static void cpsw_unregister_ports(struct cpsw_common *cpsw)
>  
>  	for (i = 0; i < cpsw->data.slaves; i++) {
>  		ndev = cpsw->slaves[i].ndev;
> -		if (!ndev)
> +		if (!ndev || ndev->reg_state != NETREG_REGISTERED)
>  			continue;
>  
>  		priv = netdev_priv(ndev);
> @@ -1494,7 +1494,6 @@ static int cpsw_register_ports(struct cpsw_common *cpsw)
>  		if (ret) {
>  			dev_err(cpsw->dev,
>  				"cpsw: err registering net device%d\n", i);
> -			cpsw->slaves[i].ndev = NULL;
>  			break;
>  		}
>  	}

-- 
Alexander Sverdlin.

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

* Re: [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path
  2026-02-05  2:47 [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path Kevin Hao
  2026-02-05  2:47 ` [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in " Kevin Hao
  2026-02-05  2:47 ` [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet Kevin Hao
@ 2026-02-06  3:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-02-06  3:10 UTC (permalink / raw)
  To: Kevin Hao
  Cc: netdev, s-vadapalli, rogerq, andrew+netdev, davem, edumazet, kuba,
	pabeni, vladimir.oltean, saeedm, daniel.zahka, lorenzo,
	alexander.sverdlin, nicolas.dichtel, m-karicheri2,
	ilias.apalodimas, grygorii.strashko, linux-omap, stable

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 05 Feb 2026 10:47:01 +0800 you wrote:
> These two patches address duplicate or unnecessary netdev unregistration
> in the cpsw_probe() error handling path.
> 
> ---
> Cc: Siddharth Vadapalli <s-vadapalli@ti.com>
> Cc: Roger Quadros <rogerq@kernel.org>
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
> Cc: Saeed Mahameed <saeedm@nvidia.com>
> Cc: Daniel Zahka <daniel.zahka@gmail.com>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>
> Cc: Alexander Sverdlin <alexander.sverdlin@gmail.com>
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Cc: Murali Karicheri <m-karicheri2@ti.com>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: Grygorii Strashko <grygorii.strashko@ti.com>
> Cc: linux-omap@vger.kernel.org
> Cc: stable@vger.kernel.org
> 
> [...]

Here is the summary with links:
  - [net,1/2] net: cpsw_new: Fix unnecessary netdev unregistration in cpsw_probe() error path
    https://git.kernel.org/netdev/net/c/62db84b7efa6
  - [net,2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet
    https://git.kernel.org/netdev/net/c/9d724b34fbe1

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] 6+ messages in thread

end of thread, other threads:[~2026-02-06  3:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05  2:47 [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path Kevin Hao
2026-02-05  2:47 ` [PATCH net 1/2] net: cpsw_new: Fix unnecessary netdev unregistration in " Kevin Hao
2026-02-05 19:03   ` Alexander Sverdlin
2026-02-05  2:47 ` [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet Kevin Hao
2026-02-05 19:03   ` Alexander Sverdlin
2026-02-06  3:10 ` [PATCH net 0/2] net: cpsw_new: Fix multiple issues in the cpsw_probe() error path 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