public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hao <haokexin@gmail.com>
To: netdev@vger.kernel.org
Cc: Siddharth Vadapalli <s-vadapalli@ti.com>,
	 Roger Quadros <rogerq@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	 Vladimir Oltean <vladimir.oltean@nxp.com>,
	 Saeed Mahameed <saeedm@nvidia.com>,
	Daniel Zahka <daniel.zahka@gmail.com>,
	 Lorenzo Bianconi <lorenzo@kernel.org>,
	 Alexander Sverdlin <alexander.sverdlin@gmail.com>,
	 Nicolas Dichtel <nicolas.dichtel@6wind.com>,
	 Murali Karicheri <m-karicheri2@ti.com>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	 Grygorii Strashko <grygorii.strashko@ti.com>,
	linux-omap@vger.kernel.org,  stable@vger.kernel.org,
	Kevin Hao <haokexin@gmail.com>
Subject: [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet
Date: Thu, 05 Feb 2026 10:47:03 +0800	[thread overview]
Message-ID: <20260205-cpsw-error-path-v1-2-6e58bae6b299@gmail.com> (raw)
In-Reply-To: <20260205-cpsw-error-path-v1-0-6e58bae6b299@gmail.com>

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


  parent reply	other threads:[~2026-02-05  2:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Kevin Hao [this message]
2026-02-05 19:03   ` [PATCH net 2/2] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260205-cpsw-error-path-v1-2-6e58bae6b299@gmail.com \
    --to=haokexin@gmail.com \
    --cc=alexander.sverdlin@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel.zahka@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=grygorii.strashko@ti.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=m-karicheri2@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=pabeni@redhat.com \
    --cc=rogerq@kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=saeedm@nvidia.com \
    --cc=stable@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox