From nobody Sun Feb 8 14:07:37 2026 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 CAE062F6565 for ; Fri, 31 Oct 2025 16:05:47 +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=1761926751; cv=none; b=BBhCnrMPlmtW+tO27OsgLXfZtmLYclgOMgchAnRn1RcgLM2dmNvPwViQtQH7FJKZxjwlm+RDm7yZ5DPQ8wcba7WIx4qCRILzV7K+/6XdZRgE7q5+95fsr/283dVMctN9KmHD3b9xKkOpI/mQ7NzrK3DzQaerZJu/RSHMT8U6GvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761926751; c=relaxed/simple; bh=3d1DuZvw7GhJQXpyQHyp6TlWMnFB6JacNbOWw4apjd4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eR1vyHQU4aW+c65cMlyByRDv0QXWljs21wAx/ymUz2U3767k6zJ2iRqUzIXmAjUDObcwzbhPaH/40ibXt6d6OX5W3zzPMQhRqYSLn0XckpPMNDW/aXlOqigzizz1P4KbqTHTTwADywOn9GBqtqSVTy1bmUBTBAlI3tQb5DG4HS8= 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=bek9I4ye; 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="bek9I4ye" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 91774C0E958; Fri, 31 Oct 2025 16:05:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 208B860704; Fri, 31 Oct 2025 16:05:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2F1381181806A; Fri, 31 Oct 2025 17:05:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761926745; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=QEtK9IwqBQGH9Hqj1vjCH38ZZQWDdIg1bt9DARfiyGU=; b=bek9I4ye8XrgktPI+be1SY1Gv6X8TIGjIAnNhDRVaSs/YT3JULnaRG/i7o16HSsbyRs5og OLbcx4IXiE75VYukU8PVkyaPluSVjee+U72SMAmZUke+6BTc+RWKQ42W3F9ZWIv2CqDvld lO/uVRo+VFQ0hU5bZzODhQSahulTm+F5rI/kmzoWbl/YuFMSh5YMEesIr7+Ml6aI0IwntK gsy4V9P3wBauiKMOF8SQJrG3uWCTFZlGPYGJb5rEK7n5kmegwXcQy/j8JzU9veYIgYbUTo e4NQM9ELwQk3HGAzpkxNV/Hl+HKVNE1cuevkYVx4aEFou/3etDtWrrpnhbtNvg== From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 31 Oct 2025 17:05:38 +0100 Subject: [PATCH net 1/3] net: dsa: microchip: Fix checks on irq_find_mapping() 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: <20251031-ksz-fix-v1-1-7e46de999ed1@bootlin.com> References: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> In-Reply-To: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran 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)" X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 irq_find_mapping() returns a positive IRQ number or 0 if no IRQ is found but it never returns a negative value. However, on each irq_find_mapping() call, we verify that the returned value isn't negative. Fix the irq_find_mapping() checks to enter error paths when 0 is returned. Return -EINVAL in such cases. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 8 ++++---- drivers/net/dsa/microchip/ksz_ptp.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index a962055bfdbd8fbfc135b2dec73c222a213985c4..3a4516d32aa5f99109853ed400e= 64f8f7e2d8016 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2583,8 +2583,8 @@ static int ksz_irq_phy_setup(struct ksz_device *dev) =20 irq =3D irq_find_mapping(dev->ports[port].pirq.domain, PORT_SRC_PHY_INT); - if (irq < 0) { - ret =3D irq; + if (!irq) { + ret =3D -EINVAL; goto out; } ds->user_mii_bus->irq[phy] =3D irq; @@ -2948,8 +2948,8 @@ static int ksz_pirq_setup(struct ksz_device *dev, u8 = p) snprintf(pirq->name, sizeof(pirq->name), "port_irq-%d", p); =20 pirq->irq_num =3D irq_find_mapping(dev->girq.domain, p); - if (pirq->irq_num < 0) - return pirq->irq_num; + if (!pirq->irq_num) + return -EINVAL; =20 return ksz_irq_common_setup(dev, pirq); } diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchi= p/ksz_ptp.c index 35fc21b1ee48a47daa278573bfe8749c7b42c731..c8bfbe5e2157323ecf29149d190= 7b77e689aa221 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1139,8 +1139,8 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p) irq_create_mapping(ptpirq->domain, irq); =20 ptpirq->irq_num =3D irq_find_mapping(port->pirq.domain, PORT_SRC_PTP_INT); - if (ptpirq->irq_num < 0) { - ret =3D ptpirq->irq_num; + if (!ptpirq->irq_num) { + ret =3D -EINVAL; goto out; } =20 --=20 2.51.0 From nobody Sun Feb 8 14:07:37 2026 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 3181D2ED86F for ; Fri, 31 Oct 2025 16:05:49 +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=1761926750; cv=none; b=Mp1JEeWBqzGFYdCob1xxTkhEtP7HkvZLmR5DAsQEiV3z/CLlSV2giN3JP7CWvyVhPTl4fzVyyqupodDhY8qsMDJWlWPKqRQ59JhdZuKzPaovNRR1jnSoKowm/0SI4Yd1pnBCMXyI6xeOjwmwSro9hGcrDGHTRK2bTIFIUfrnpDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761926750; c=relaxed/simple; bh=JcnwdY8lRx59kxN7gAwOccPBuzqdGKNApvQA0+Faz40=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qItevAzIDXxFaci65re0+OuOsaOOeH4V13lSaeKEAzBsyRfQy/Ujp0DmnUAsNB3AAq1/ZyaU7W1waMUyol4lF+iOANnOS8glv2ld0NRTTHqXyCTRWK4swoarwEf+KX7U/GMUbBnKrkhiDwFoCRUzJu5jULCedVyAw+EoayEiORs= 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=oLeN7eW2; 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="oLeN7eW2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 866B21A17B1; Fri, 31 Oct 2025 16:05:47 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5DE1860704; Fri, 31 Oct 2025 16:05:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9DAD31181806D; Fri, 31 Oct 2025 17:05:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761926746; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=SuE1P/t3JhQxGDqkLTlGxkPzTN+VoYUJlI/OuU0IJZ8=; b=oLeN7eW2SJJheRVLrP64qKAWC1cV4qxKr64rW29/TW1S558J3lK8kKLMwttmvvZEONTmI5 +fyBM+yuoJR86GSSfyZvlQ6f+bf61a/AdB4mT24w97bttq1KUBzZjo4mAphrVOBiO50371 yFmkxmDnI7sJ2xtyvBCScDcDxC3o49p8DC5/qua4SRIMw2VffsLh+70/Iw53I93E8yTboZ R02/3By19voR4nMYm3DLyU5g7uFY7UW97jjroXhYjPnU22FgIm3FohJ1WkRUjirYNEECOJ xzraihbauy/OBWxXAoqJk96+YGURa03c4ijtOfDjK9lQLzJh8OFya6Vxfea4Lw== From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 31 Oct 2025 17:05:39 +0100 Subject: [PATCH net 2/3] net: dsa: microchip: Ensure a ksz_irq is initialized before freeing it 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: <20251031-ksz-fix-v1-2-7e46de999ed1@bootlin.com> References: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> In-Reply-To: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran 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)" X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Sometimes ksz_irq_free() can be called on uninitialized (or partially initialized) ksz_irq. It leads to freeing uninitialized IRQ numbers and/or domains. Ensure that IRQ numbers or domains are initialized before freeing them. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 3a4516d32aa5f99109853ed400e64f8f7e2d8016..4f5e2024442692adefc69d47e82= 381a3c3bda184 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2858,14 +2858,16 @@ static void ksz_irq_free(struct ksz_irq *kirq) { int irq, virq; =20 - free_irq(kirq->irq_num, kirq); + if (kirq->irq_num) + free_irq(kirq->irq_num, kirq); =20 for (irq =3D 0; irq < kirq->nirqs; irq++) { virq =3D irq_find_mapping(kirq->domain, irq); irq_dispose_mapping(virq); } =20 - irq_domain_remove(kirq->domain); + if (kirq->domain) + irq_domain_remove(kirq->domain); } =20 static irqreturn_t ksz_irq_thread_fn(int irq, void *dev_id) --=20 2.51.0 From nobody Sun Feb 8 14:07:37 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 B63632F693E; Fri, 31 Oct 2025 16:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761926752; cv=none; b=sBZTTpOrQ9ZZMJXSKXrRu2LBEdJF/V4m5JsMyqcuEBQ/f8RpQYjbV6fwWu7rYoWmulRY0KT1Rv5xqDn7TGYs5qxiSvxoEIkKGzM/whYTRCj+2F1aAIf7QETC1jOf6KqnY9fqzgi7Qt3XITvTtZiJhiw8YFc/cnGGVOgWd+J+ACU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761926752; c=relaxed/simple; bh=95X8NfNg94Ut5ngq92r3DA5Bj+TwY3d3z4iHIBxI1SI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JBZjicEE6DJKEPL9kTJ+whqVA1azcGNSVFrG+9sZfxMmv9D4xM77Y63mtnrzm20nCAZanyAdZqXYSzJWIeZYNytAusTCqbfLeXkE2889tjepHoH6EFEanQ61yB0ZS4KgFw5+MWDyag1Nw5A/tcwpbdaL90g8ptzoFetceysJGQs= 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=r/Eg/NM9; arc=none smtp.client-ip=185.246.85.4 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="r/Eg/NM9" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id E8B3B4E41445; Fri, 31 Oct 2025 16:05:48 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id BFB0260704; Fri, 31 Oct 2025 16:05:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0DFA511818067; Fri, 31 Oct 2025 17:05:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761926748; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=lo3kX3rnuQel+DCOioyxlIMM2H/4F/tW6UiRMe3mpSw=; b=r/Eg/NM9wAN7B/lEvAH/7SeK4ifGkCo9EPiCrT5CP0328hJO4vDoD+Uv5Mq4J2SCgzo+4g PGBPV05ydRhdkXovgas4BwohBayeChJ/7tHqdSqmpEuAR11hL4GYy56Cc9TKSE637j3UBA wfnJvUBI3gD71fMY6B9yBJo1HWiujRpqciGrECY0BhtuhEg6ojmLmXv8viAyALZuf8konV Nt2+8vtKOeKxuWXffAvkoVxkvuorxcOdcWecCo39nmcUR9MDucyiFCKntp5W9QB8uItvXr mNVVzlkfKlQlrLip+Fw5Mjg2UE39avqRr1qRuLYpoEFcY87mNAkt4MxqRlQ5PA== From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 31 Oct 2025 17:05:40 +0100 Subject: [PATCH net 3/3] net: dsa: microchip: Immediately assing IRQ numbers 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: <20251031-ksz-fix-v1-3-7e46de999ed1@bootlin.com> References: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> In-Reply-To: <20251031-ksz-fix-v1-0-7e46de999ed1@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran 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)" 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 try to release the not yet assigned ptpmsg_irq[n].num. Assing the IRQ number at mapping creation. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_ptp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchi= p/ksz_ptp.c index c8bfbe5e2157323ecf29149d1907b77e689aa221..a8ad99c6ee35ff60fb56cc57705= 20a793c86ff66 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1102,10 +1102,6 @@ static int ksz_ptp_msg_irq_setup(struct ksz_port *po= rt, u8 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,8 +1131,13 @@ 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); + for (irq =3D 0; irq < ptpirq->nirqs; irq++) { + port->ptpmsg_irq[irq].num =3D irq_create_mapping(ptpirq->domain, irq); + if (!port->ptpmsg_irq[irq].num) { + ret =3D -EINVAL; + goto out; + } + } =20 ptpirq->irq_num =3D irq_find_mapping(port->pirq.domain, PORT_SRC_PTP_INT); if (!ptpirq->irq_num) { --=20 2.51.0