From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8EE31DE8AE; Sun, 7 Jun 2026 10:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780826949; cv=none; b=NLg8MR4QAyy2UDPenS3DdKMMCy4X7PmX9eYhGG/jh9qUFpAcqfE1n24228rfdAsKIeSluo7v6h2JP4wIX5C5dncVPTPogwIB9jt5Ab62hsBL7UPQv4trBOIUHTX3NzsKlWIv7g7KaW4nDjdvbE39+SKc06I64P2lBq+21O2kkn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780826949; c=relaxed/simple; bh=8nhmbYsHwTGNx2fm3R5vsDPLJHl4v863079xCU5yTPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZhmHFpWIEpq3CwcHCs7cgdlX/wSHMb5XAeZyZCaKAWQn7XPS4n4gG7EP5WTlhRDn5KHsz5+35DCZbZ6MmUs3OjqyC9IfOOcLDvXNuPE2SpBAHAFarzhzn8FGbBDV58IlIyI+ZYHmQWYelhmIoe1HRITbtHYl6rfTHpaTU8+6CFs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1wJE8x4z; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1wJE8x4z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 279A41F00893; Sun, 7 Jun 2026 10:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780826948; bh=sElsDtRTBFYuCGgTtcMGeJ7z3Gt7XGO7wIMdDdRZtgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1wJE8x4zNKMQucjKMgaMq/i5/5yLGPVYxc5q0V4f5rJHsdr6Q5FQ2djJwd7/C0C7M NxYmmnQ4DsikyVkOYEH1NPqAsjJtE9UfMDbTZK+itAhEZGGeTzG0Nrf6UZ3cIoQUbE UIPF+adblcoRgCfcLQB/Jse3hyfGpDul332ZUwRA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kevin Hao , Alexander Sverdlin , Jakub Kicinski , Wenshan Lan , Sasha Levin Subject: [PATCH 6.12 009/307] net: cpsw_new: Fix potential unregister of netdev that has not been registered yet Date: Sun, 7 Jun 2026 11:56:46 +0200 Message-ID: <20260607095727.979913338@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607095727.647295505@linuxfoundation.org> References: <20260607095727.647295505@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kevin Hao [ Upstream commit 9d724b34fbe13b71865ad0906a4be97571f19cf5 ] 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 Cc: stable@vger.kernel.org Reviewed-by: Alexander Sverdlin Link: https://patch.msgid.link/20260205-cpsw-error-path-v1-2-6e58bae6b299@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Wenshan Lan Signed-off-by: Sasha Levin --- drivers/net/ethernet/ti/cpsw_new.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index a74caaca94d110..fa161a10960459 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -1443,7 +1443,8 @@ static void cpsw_unregister_ports(struct cpsw_common *cpsw) int i = 0; for (i = 0; i < cpsw->data.slaves; i++) { - if (!cpsw->slaves[i].ndev) + if (!cpsw->slaves[i].ndev || + cpsw->slaves[i].ndev->reg_state != NETREG_REGISTERED) continue; unregister_netdev(cpsw->slaves[i].ndev); @@ -1463,7 +1464,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.53.0