From nobody Tue Dec 2 02:19:51 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 7AF3F31691C for ; Thu, 20 Nov 2025 09:12:21 +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=1763629943; cv=none; b=WuYfm7+8+mO1tROrGVhB2piAMze9UvzXQ5/4T7kAFYCEcL0iqyrIxhB/ym3gXBeCcvvBv7eUzz/SOroJUF/V2MlZVfpKdOsBrLJSQCcXbPaePCTBeDm9GfJHpQKqlSBoCu9gCwjlTCowpS0Ub/Jg6/w4tTq9mWJl/9jdbog0PVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629943; c=relaxed/simple; bh=Fr95gr2MS+4E19O9tKTmnf7ACBsyrmSMrq1dJf/vZk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=flFTT76rThsjV6/lECgDZpipaBmmaOost/qWhga/oSOOPn6quUQCURFJ28nySuDmyt5PJQvnIzMyZA8J1G1s1kRnP6uVojAt37KP7bidY6JoNW0U849fGIniD1+ucbcUGK0J/ikoaFTK1ALR6Q+kFE02RJUTYZT9Lar/As82fAo= 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=DV3Hw/Vd; 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="DV3Hw/Vd" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id CFBF1C111B2; Thu, 20 Nov 2025 09:11:57 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 244286068C; Thu, 20 Nov 2025 09:12:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CA66910371C08; Thu, 20 Nov 2025 10:12:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763629939; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=6PmstxobF6Y4mA2z1PMwswOGcY6Z1dVMYzIEo3cJgeM=; b=DV3Hw/VdLCIYqVARSkaBflhiYbE1MhDD7RoQswQDkztPcjY8ml0iDrzh54PQ/n5M8Ccii1 tkgTF5pPsZxbX/hvF8k/S8gCPtstIvfAxw9L+aRxksKvIMBR3t7jyTL6okx4rljViEMyOZ Xblox8LGo6MkL58eoPD0gRO3PPUc6T3lNupq0qBB6w6gCWPbxqJP9QZ3q/M5OIFgP7ORmU GqcpQ6bPrDpcj2qk3qyoxRXu/1bY68Xn/p45mx1HUkzOdEC434CD6zFYfyFvDzREtMB1tT bSxS+A3Rl86KL1X2RvAZFYqIahhmk2XTD5nPfoLe3IjC9PRjGUL7fvt3ojhPnA== From: "Bastien Curutchet (Schneider Electric)" Date: Thu, 20 Nov 2025 10:12:04 +0100 Subject: [PATCH net v6 5/5] net: dsa: microchip: Fix symetry in ksz_ptp_msg_irq_{setup/free}() 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-5-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 The IRQ numbers created through irq_create_mapping() are only assigned to ptpmsg_irq[n].num at the end of the IRQ setup. So if an error occurs between their creation and their assignment (for instance during the request_threaded_irq() step), we enter the error path and fail to release the newly created virtual IRQs because they aren't yet assigned to ptpmsg_irq[n].num. Move the mapping creation to ksz_ptp_msg_irq_setup() to ensure symetry with what's released by ksz_ptp_msg_irq_free(). In the error path, move the irq_dispose_mapping to the out_ptp_msg label so it will be called only on created IRQs. Cc: stable@vger.kernel.org Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timest= amping") Reviewed-by: Andrew Lunn Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_ptp.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchi= p/ksz_ptp.c index c8bfbe5e2157323ecf29149d1907b77e689aa221..997e4a76d0a68448b0ebc761691= 50687bbc79673 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1093,19 +1093,19 @@ static int ksz_ptp_msg_irq_setup(struct ksz_port *p= ort, u8 n) static const char * const name[] =3D {"pdresp-msg", "xdreq-msg", "sync-msg"}; const struct ksz_dev_ops *ops =3D port->ksz_dev->dev_ops; + struct ksz_irq *ptpirq =3D &port->ptpirq; struct ksz_ptp_irq *ptpmsg_irq; =20 ptpmsg_irq =3D &port->ptpmsg_irq[n]; + ptpmsg_irq->num =3D irq_create_mapping(ptpirq->domain, n); + if (!ptpmsg_irq->num) + return -EINVAL; =20 ptpmsg_irq->port =3D port; ptpmsg_irq->ts_reg =3D ops->get_port_addr(port->num, ts_reg[n]); =20 strscpy(ptpmsg_irq->name, name[n]); =20 - ptpmsg_irq->num =3D irq_find_mapping(port->ptpirq.domain, n); - if (ptpmsg_irq->num < 0) - return ptpmsg_irq->num; - return request_threaded_irq(ptpmsg_irq->num, NULL, ksz_ptp_msg_thread_fn, IRQF_ONESHOT, ptpmsg_irq->name, ptpmsg_irq); @@ -1135,9 +1135,6 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p) if (!ptpirq->domain) return -ENOMEM; =20 - for (irq =3D 0; irq < ptpirq->nirqs; irq++) - irq_create_mapping(ptpirq->domain, irq); - ptpirq->irq_num =3D irq_find_mapping(port->pirq.domain, PORT_SRC_PTP_INT); if (!ptpirq->irq_num) { ret =3D -EINVAL; @@ -1159,12 +1156,11 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p) =20 out_ptp_msg: free_irq(ptpirq->irq_num, ptpirq); - while (irq--) + while (irq--) { free_irq(port->ptpmsg_irq[irq].num, &port->ptpmsg_irq[irq]); -out: - for (irq =3D 0; irq < ptpirq->nirqs; irq++) irq_dispose_mapping(port->ptpmsg_irq[irq].num); - + } +out: irq_domain_remove(ptpirq->domain); =20 return ret; --=20 2.51.1