From nobody Tue Dec 2 02:19:52 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 3D9E931159C; Thu, 20 Nov 2025 09:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629942; cv=none; b=cHUwJ/FtDx4Sm5WWT4l3t5TRlcCZxL2uzjjsCUaALVzVjTiWndxZKi35fquGsTt3xEq+h/Zn8da3AIWH3zUcOCAnvnWNIDRFJOXmwJUpRLMLjpQFZf04nF/6E8Iy9Gd7cn7OMUTAl7nDD+8ig6M0q/Cmoo9k2BbpJqVOmi/ekcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629942; c=relaxed/simple; bh=SNc9KPd+VYHuuljc4tikPeoiw2/FRlkt35tVrY/RNtY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=udjm9x2lioz8ys5dDPlxng5BihCjuIlutPJlQeJgh3irHnXJGcacIT0QljMi+v+v33wY+k1j/r7Q3OjZ6CKE1eF20xJJKAaU8OCJG6alTCTNeyWodNJF/js/UlXEzvu8cL53ei3oEe3v/Pz5Y692obzJAgzCz5uIOjN+dMdPLdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ZVPA2g8W; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ZVPA2g8W" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 0EDF0C111B4; Thu, 20 Nov 2025 09:11:56 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 571116068C; Thu, 20 Nov 2025 09:12:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2A23F10371A64; Thu, 20 Nov 2025 10:12:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763629937; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=3j+6mNknD1aW1qj4otEZViSzAhGSD7ROl3O0W3MuHtk=; b=ZVPA2g8WbLtAWb5PA+mQwaNm/rZqun9vNJCgLPuw+3JfEL9s//CN/d2CSTDA/yQ+t65+b8 mkIWu5hiSV16MaM52hwYWx/X2FtE7xJQZRiVxVhv7+vCUh6D9j87NYUfiHqEiKhRanj5uP vlwfq5BWywWKybgsz2U3FIP21dI7HkAA4FVLqDEH3Jp6eImka23PLZn8WxbGUobLQT4Fhg fEO7fDS9vnmjhzy5aNyTCufhF+dPatt2/3TMyTr649aBdg7zYq1dxoqJ8WId1Ts/QTjOUH Gmn9xL2E81gu+wcDsI2tqe4xsHcQlZ0PAVCWyns1lPq3j+6zWrkT2d/rorM9pg== From: "Bastien Curutchet (Schneider Electric)" Date: Thu, 20 Nov 2025 10:12:03 +0100 Subject: [PATCH net v6 4/5] net: dsa: microchip: Free previously initialized ports on init failures Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251120-ksz-fix-v6-4-891f80ae7f8f@bootlin.com> References: <20251120-ksz-fix-v6-0-891f80ae7f8f@bootlin.com> In-Reply-To: <20251120-ksz-fix-v6-0-891f80ae7f8f@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Arun Ramadoss Cc: Pascal Eberhard , =?utf-8?q?Miqu=C3=A8l_Raynal?= , Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (Schneider Electric)" , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 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 f= or port phy link") Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 49827ac770e6fcc9e4a1a11e8814cdd90b17473e..96f37b8e72d160aeb265ef9c4d4= 9f81d1c23abd9 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3036,12 +3036,12 @@ static int ksz_setup(struct dsa_switch *ds) dsa_switch_for_each_user_port(dp, dev->ds) { ret =3D ksz_pirq_setup(dev, dp->index); if (ret) - goto out_girq; + goto port_release; =20 if (dev->info->ptp_capable) { ret =3D ksz_ptp_irq_setup(ds, dp->index); if (ret) - goto out_pirq; + goto pirq_release; } } } @@ -3051,7 +3051,7 @@ static int ksz_setup(struct dsa_switch *ds) if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", ret); - goto out_ptpirq; + goto port_release; } } =20 @@ -3074,17 +3074,16 @@ static int ksz_setup(struct dsa_switch *ds) out_ptp_clock_unregister: if (dev->info->ptp_capable) ksz_ptp_clock_unregister(ds); -out_ptpirq: - if (dev->irq > 0 && dev->info->ptp_capable) - dsa_switch_for_each_user_port(dp, dev->ds) - ksz_ptp_irq_free(ds, dp->index); -out_pirq: - if (dev->irq > 0) - dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) +port_release: + if (dev->irq > 0) { + dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) { + if (dev->info->ptp_capable) + ksz_ptp_irq_free(ds, dp->index); +pirq_release: ksz_irq_free(&dev->ports[dp->index].pirq); -out_girq: - if (dev->irq > 0) + } ksz_irq_free(&dev->girq); + } =20 return ret; } --=20 2.51.1