From nobody Tue Dec 2 02:43:02 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 DBF9C393DC0; Tue, 18 Nov 2025 16:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482420; cv=none; b=kTxxNBAVkOP/xsdbCzMF3x/cfpbskEay93uA6LHKSN/w8hYM5CrSQcZyHZw92OalF11LUAzephm0RWd/P1L2ERe8TLuomL2+G8vLOXYLMCZBkiAJjP7ZSU/8zBdZAw0C0TZ3DmKbpE3pQUBcTug9GGqqS1wb4Mi49W712rKatqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482420; c=relaxed/simple; bh=urZCwgO9eY5wzMDt4S438Ky7zIoBTVXf/9dj9AQNTgk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e+2het69VRe8Y7fHehdC3XfHj9vqfTyfgkj5FGqW976XHUcR/++WQ6/wVGrJAZIGLkQJd5Tc68DqW9w0kyKI4E072d2T8sYXoOVgjDfyRjEJUOL1R9Rtej3sSrbzze1aiFyehrKO4l7C5UR4+c02PACSZUkKHtskstQsrpUbR6g= 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=Di/Wfzah; arc=none smtp.client-ip=185.246.84.56 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="Di/Wfzah" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 43DBC1A1B93; Tue, 18 Nov 2025 16:13:37 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1A9EF606FE; Tue, 18 Nov 2025 16:13:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 058C110371E69; Tue, 18 Nov 2025 17:13:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763482416; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=fQJ6cySyzEDMElTvPdLkDFf4bBvb2ZHUfIoGJQAGJl0=; b=Di/WfzahsP8zC5Q5ZQhKnWg3Z6uW9z9rj9XqzhqxuhWU3rqffgNeckegHfObHl9bREzGFs j6cmPloo2N0u+B9OX76HatodmIFjEeD7bvLVLVw9CP2q0LMUbhVM/WX0vZ0ONBX1MSCuGn d2X9JXJWY7UbYmKo2yWd+DEwnHO1ofBATQoSRUXadogqK/zJwAMXyKrIKzzZaVgwATQb4K pOkNHENrh/yE55PYqc37Pkc5NV9IshEJCz9YwDnNrKuxZBPO5mqhS3YWhwBO838bQ76tuM R9o/2OCbylbFzS45bmYQfShhPosT9B2Wc3lP4eN509QLeslN2S4BiLkKp/Qfbg== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 18 Nov 2025 17:13:26 +0100 Subject: [PATCH net v5 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: <20251118-ksz-fix-v5-5-8e9c7f56618d@bootlin.com> References: <20251118-ksz-fix-v5-0-8e9c7f56618d@bootlin.com> In-Reply-To: <20251118-ksz-fix-v5-0-8e9c7f56618d@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") Signed-off-by: Bastien Curutchet (Schneider Electric) Reviewed-by: Andrew Lunn --- 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