From nobody Tue Dec 2 02:05:17 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 3EBC730CDA8; Thu, 20 Nov 2025 09:12:15 +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=1763629937; cv=none; b=lqozFcE0pC7whLLy7LwIbM8+obcAhPyyUGh2rwTyuJMY5Ncf16rJl3cZiv1/RNHrTw0Fq1kOA7yYvgvdtU1e9jWsGP/UYmCqoBZ+be+QRikctcuJ0GTgcSG5ZMaIzAXJWfXMGaUuAuzlVNatR33GfNfXcG/9jNNwWPYAHYzAKbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629937; c=relaxed/simple; bh=/TAZ0MNDd7KPjWRWFfY6/kmUBIYyi1aJS8Zgiq7UBLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PWaVj5Oy6SHTbaP5OGHWHGy9dfym3khzAAhvinvcxavjhM0QCfEoYyNNOuCeaHLnnhEKRlWZga9VZT4s/m8S3n79oIYv5MGxAIYeio9c/RxvhRDiZsPMjd6gR8oY/ZOvjpqj14EBno3uxeT5M2H3yv2RY05JM12doHTz0ziFvVI= 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=GyAEBqR7; 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="GyAEBqR7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 57524C111B4; Thu, 20 Nov 2025 09:11:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A047E6068C; Thu, 20 Nov 2025 09:12:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9170F10371A64; Thu, 20 Nov 2025 10:12:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763629932; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=2tUIB0M+kOJqzAWgjucjSvzqi0jzDm+l3AVxpf2oZb4=; b=GyAEBqR7/BS4ttKqtMj1qkAe0WewyugViNk8DjpI7PRdd5dAXkNp0vldtcYIqIcqAvJdql Yn50tp6XzAnD6RgKJin6wDozg7rA5YkzurGqb+QqVCgt/Q9HS40+vf4eWX4H89LvgRJ8cf bavUGRF3wikFuk8oCc2xHpSC5CWlB+Xyll88nu/HP9Hn5NAsSwwS/PRYxHf4COH3Qa/BPf plyWSUSHFOn2UFAyrn9wiKTGlxby41bTX4tM2eQRLnCThZF+2dzNz/0LsYoRsIHt7s9q7b eZOx3adQs6wtewU4DATp9b+nD0AwSAW0/0hESBFm1cdBH8bpweN+9vL9SBFGSA== From: "Bastien Curutchet (Schneider Electric)" Date: Thu, 20 Nov 2025 10:12:00 +0100 Subject: [PATCH net v6 1/5] net: dsa: microchip: common: 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: <20251120-ksz-fix-v6-1-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 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. CC: stable@vger.kernel.org Fixes: c9cd961c0d43 ("net: dsa: microchip: lan937x: add interrupt support f= or port phy link") Reviewed-by: Andrew Lunn Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 98cfb42b7257b8e3b4b5cce4bbf97def64537370..b17d29dda612ce00ce2e52fbe16= c54bd6516c417 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2585,8 +2585,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; @@ -2950,8 +2950,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); } --=20 2.51.1 From nobody Tue Dec 2 02:05:17 2025 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 DD0063126B1 for ; Thu, 20 Nov 2025 09:12:16 +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=1763629938; cv=none; b=oXDupoSxQOjGkcg0QAiL5VnKyxunsl37s+narzUulOPqmvczsO/IP37W8NX5wA0Iz2zEMcop1bFKWd+pmd15jxeD6sKlcjp1/3EMiWr0mpDg4uoYkJ3AFn83mihcig75wTmiSMxpZFF5LnkHLNG5TXHNflN+TR/isKXckmypMi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629938; c=relaxed/simple; bh=AEmkrFjqifoQnRxMtvLlTc3t/RLufAY+GpBg7zW6NZI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C2GIV4joedDGStb47rc8eKN/wFF547rzlS+dpfbAIV3Xnr+2s65tWqnsZsOrkz8p6fiuNVJisvFsw95QRfHdCGaPqpUj40wSnE/IIQhcQwNT10d+rKALki47YNvABe8KtSvDEXKI1Yyx1IgjUs13FEH3brjGjrLmZewgdRquN5c= 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=DB6hxTh3; 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="DB6hxTh3" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 4F2864E417E1; Thu, 20 Nov 2025 09:12:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 255576068C; Thu, 20 Nov 2025 09:12:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D2ECA10371C0B; Thu, 20 Nov 2025 10:12:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763629934; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=PtjJwnZbSztJ0ylhjAx5WuFm6ywuzKa2m4FJNifI2/U=; b=DB6hxTh3ch+YWeDlN8YahCmb1mUPG3v428civqRVeubz+jt45GH4H6C5M8vSWgUV0Jw9fH eUTm0D1IoOMEkOZKJpAqdE7swG2XoCsRLRmPh/3EN3ypUHi361m2JnV8r65wae7P0FbWnX E5B5/IiHDjBjJmiWZk3gmz9bTR+GC3NmkgvPriHra6nPzNBwph2UDTWCycPz/+TEP2cFzm jzh+nHILmIWly/bJhKX5p0/kudhQndzsCCWyS+weTdK+Oh3ofyUC/5MBM5Vzqk2LzjxoRR m4gRHx+4WJlbxR8mWSpqMRiohn6BgmhtCFeeanfVou9arsMYVT/7UBekA/mmyw== From: "Bastien Curutchet (Schneider Electric)" Date: Thu, 20 Nov 2025 10:12:01 +0100 Subject: [PATCH net v6 2/5] net: dsa: microchip: ptp: 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: <20251120-ksz-fix-v6-2-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 irq_find_mapping() returns a positive IRQ number or 0 if no IRQ is found but it never returns a negative value. However, during the PTP IRQ setup, we verify that its returned value isn't negative. Fix the irq_find_mapping() check to enter the error path when 0 is returned. Return -EINVAL in such case. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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.1 From nobody Tue Dec 2 02:05:17 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 9CD5B3148CD; Thu, 20 Nov 2025 09:12:18 +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=1763629941; cv=none; b=ha6md6iHu5O25SpNluobNa5ucLmnQV2xfJhXwPTQs9xWMy4Y0t1OrhaVEn2G1Vj8T4DFhYSdNfG+tDF38Oxg73cmlZeufMUVIx0vDnSvpvszB/dad6oDz/R4T1/u8LhfgCYGNNjGsiQBwHv8KQG3d6txb5UXvZyM7IYgQqDvv7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763629941; c=relaxed/simple; bh=R2ZCVf/VJ+iRyopKoIirxw/rsKraQlQIQ1btffSMMzE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L6qqQpC5BsGxk1RI7OzB9+s9ZqR01KjjIlIqf8keqN2gy7QdM4Kcis2lsgTXaFxpK4rWU3FeCw+B7i8dX7kWWhPVniS2/iYPeSytgQxsqsY5fw2Ha2dnkumin+B2KMnVejfFR7tXFMRKCrtsnhKArKTnDGUEhVPPEtdjkuLD/Mc= 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=C+im4jjg; 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="C+im4jjg" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 0917C1A1C1B; Thu, 20 Nov 2025 09:12:17 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D11F36068C; Thu, 20 Nov 2025 09:12:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 95A2E10371C0C; Thu, 20 Nov 2025 10:12:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763629935; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=uxcBfrkPXkUZDJCua6/YvADKTChGewQXWcqnNL7MEe0=; b=C+im4jjg3s4gjlZQflMBdfIKdiE2eIvkG3e4496ZqMHij4t43WW4ugrXCTL8ps7n1USQyE 4/y3sc4WK2LLK5UCcr6jR73eMaOyY5gDMGEbn5q09vbxKc8S2vPb+NuVJTFPwfjlsQjlZV SNiJj6j5wG3GGRe8K0DydqmTNGvCRtIUGACoLltTTApNjWB1OHSveUVEhhI8O8aHScuUH0 dm1l7LSz/RHz5mLqbMG5yh7QNDgJWnY/t/EUHpu9Jrw9ZRvdpedR3OliqnY1n0thmGrcbq 6GlAt9FOZoaIMU0FtsjtxBu8KEusRYSIE7VKEfs7r3gd2IAo63v9/9isSgOM8A== From: "Bastien Curutchet (Schneider Electric)" Date: Thu, 20 Nov 2025 10:12:02 +0100 Subject: [PATCH net v6 3/5] net: dsa: microchip: Don't free uninitialized ksz_irq 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-3-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 something goes wrong at setup, ksz_irq_free() can be called on uninitialized ksz_irq (for example when ksz_ptp_irq_setup() fails). It leads to freeing uninitialized IRQ numbers and/or domains. Use dsa_switch_for_each_user_port_continue_reverse() in the error path to iterate only over the fully initialized ports. Cc: stable@vger.kernel.org Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timest= amping") Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index b17d29dda612ce00ce2e52fbe16c54bd6516c417..49827ac770e6fcc9e4a1a11e881= 4cdd90b17473e 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3080,7 +3080,7 @@ static int ksz_setup(struct dsa_switch *ds) ksz_ptp_irq_free(ds, dp->index); out_pirq: if (dev->irq > 0) - dsa_switch_for_each_user_port(dp, dev->ds) + dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) ksz_irq_free(&dev->ports[dp->index].pirq); out_girq: if (dev->irq > 0) --=20 2.51.1 From nobody Tue Dec 2 02:05:17 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 From nobody Tue Dec 2 02:05:17 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