From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3CD9F2EBB81 for ; Tue, 2 Dec 2025 20:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764706517; cv=none; b=hd5lHFIX4kFoiA7ewvbKLZvV/Xz6zVuYiNlZ8jPUMSBHq3R+TdmbJpiIjDyu4uMCZQOyz/haCWxMc73MEtGUxyo7+INKs64DVbi6QvTHmNbZm0PjNjP8XyP1sBkGulge6myYzU446Kn4gZ75SHKitv36B7veYR6ee1c5V2pCrGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764706517; c=relaxed/simple; bh=StdqYGJlXyRrM8ljPAhqWY9CQviuXaBXBx3HKjrz4xI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qNbWpRHW8tVuaNJ7JJyKTgi+Dgpl8nraaDQfp5c+JpjMebjH7EFdDq6t4/26HY8mUUH5+0LimoyFayMBeRbQaDaWMyPYwhN5DpoMj5j87grwW8lUKt7irOLhHY0IpcjkyeFD1MA96WQ2wG3qGDwPm1nIznQSS1a5UG4NYA0ZNKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LpNEsP/C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LpNEsP/C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7BCBC4CEF1; Tue, 2 Dec 2025 20:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764706516; bh=StdqYGJlXyRrM8ljPAhqWY9CQviuXaBXBx3HKjrz4xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LpNEsP/Cu/qb4nNYW5nGTQG4uORYNVw+sSdnrVg0FZy+ZoLC9kBGZqSA3/7STFtqT GdX1I3oOJ1ejNq1DLo9aVF17dVHWe2tB6QtcLh0ykvxTsN29/99PuV6YkGqp6/dWMh j2SWs/h7PyP07lXv5KDt5/A7Ub6+6BvghDTnBl3nC9xUxKblxm+4X5uXSV679VKjUw b/drTlPzISbL4/mp5zRPCj66eGlWqv/bnx2Lt1M3MSbKvqoGz8cVgjobPZ3prsxehG WCEGoNh54ynjNmMG/wHs+BCT0Fn1d1sPTe7kpOyuxgy2d2y8UDSeSkcI1IaNPAsvqZ qccKOTqTGHtfA== From: Sasha Levin To: stable@vger.kernel.org Cc: "Bastien Curutchet (Schneider Electric)" , Paolo Abeni , Sasha Levin Subject: [PATCH 6.6.y] net: dsa: microchip: Free previously initialized ports on init failures Date: Tue, 2 Dec 2025 15:15:07 -0500 Message-ID: <20251202201507.2486461-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025120249-dormitory-filtrate-415a@gregkh> References: <2025120249-dormitory-filtrate-415a@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Bastien Curutchet (Schneider Electric)" [ Upstream commit 0f80e21bf6229637e193248fbd284c0ec44bc0fd ] If a port interrupt setup fails after at least one port has already been successfully initialized, the gotos miss some resource releasing: - the already initialized PTP IRQs aren't released - the already initialized port IRQs aren't released if the failure occurs in ksz_pirq_setup(). Merge 'out_girq' and 'out_ptpirq' into a single 'port_release' label. Behind this label, use the reverse loop to release all IRQ resources for all initialized ports. Jump in the middle of the reverse loop if an error occurs in ksz_ptp_irq_setup() to only release the port IRQ of the current iteration. Cc: stable@vger.kernel.org Fixes: c9cd961c0d43 ("net: dsa: microchip: lan937x: add interrupt support for port phy link") Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20251120-ksz-fix-v6-4-891f80ae7f8f@bootlin.com Signed-off-by: Paolo Abeni [ replaced dsa_switch_for_each_user_port_continue_reverse() macro with dsa_switch_for_each_port_continue_reverse() plus manual dsa_port_is_user() check ] Signed-off-by: Sasha Levin --- drivers/net/dsa/microchip/ksz_common.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index cff83a8fb7d28..e01909ec21d7d 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2163,18 +2163,18 @@ static int ksz_setup(struct dsa_switch *ds) dsa_switch_for_each_user_port(dp, dev->ds) { ret = ksz_pirq_setup(dev, dp->index); if (ret) - goto out_girq; + goto port_release; ret = ksz_ptp_irq_setup(ds, dp->index); if (ret) - goto out_pirq; + goto pirq_release; } } ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", ret); - goto out_ptpirq; + goto port_release; } ret = ksz_mdio_register(dev); @@ -2191,17 +2191,17 @@ static int ksz_setup(struct dsa_switch *ds) out_ptp_clock_unregister: ksz_ptp_clock_unregister(ds); -out_ptpirq: - if (dev->irq > 0) - dsa_switch_for_each_user_port(dp, dev->ds) +port_release: + if (dev->irq > 0) { + dsa_switch_for_each_port_continue_reverse(dp, dev->ds) { + if (!dsa_port_is_user(dp)) + continue; ksz_ptp_irq_free(ds, dp->index); -out_pirq: - if (dev->irq > 0) - dsa_switch_for_each_user_port(dp, dev->ds) +pirq_release: ksz_irq_free(&dev->ports[dp->index].pirq); -out_girq: - if (dev->irq > 0) + } ksz_irq_free(&dev->girq); + } return ret; } -- 2.51.0