From nobody Tue Dec 2 02:33:25 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 49A603730D1; Tue, 18 Nov 2025 16:13:32 +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=1763482415; cv=none; b=BplWbNPFXn+PDOpibH9MA9l0/RRiItUoqx4qyIOqqVw86wFUmy6bqByQhpIqX/xLeczRXH/TBT6g82noOdzpraZ0hlLvpEmt/zIBUqITq+1zZFMCFQUYvbqy/3BkW8Kv8jmWZAG6xk3vY5BVT2wfxtO+8v7rTwkTBm/qaG9xDpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482415; c=relaxed/simple; bh=/TAZ0MNDd7KPjWRWFfY6/kmUBIYyi1aJS8Zgiq7UBLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=th9qqAsKeaJ+iO/MQvFsBd5B2JdOx2WQbmnCBfZy4VlE5lM6T+GsPWg5iNT7MkccrEN1q4xettMxTsCiSy/3pgw8FAsNmC1gZIAuKUUjaRMHWrl6sET15c4E4XVAyz7iKmnZuOzEmunGkZ0QR2AfjR9cx4Y4xh+K8NOQTgkA3nc= 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=HzdggdHL; 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="HzdggdHL" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 6A485C1203B; Tue, 18 Nov 2025 16:13:08 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 939B9606FE; Tue, 18 Nov 2025 16:13:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EA3A410371967; Tue, 18 Nov 2025 17:13:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763482409; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=2tUIB0M+kOJqzAWgjucjSvzqi0jzDm+l3AVxpf2oZb4=; b=HzdggdHLEYL5m6SDz4sgoT+EypXA4L6S5C+zOCW8dIZTLpLI5fvVwqgQ39UxWsgRPwnMks ll090526EptL4wKvZhQjnohgKbz4VZBo5RpYcuxOeHLmMOToSnSHjdhTWIHyBHbzxhJQe9 0zPdkFeUumweyDyxADuvbEB2Gj3qwafdl8KmoccX9RY5DiK6BsKwkDTPfa6C5Hsrt2RGn8 6tq0jYQzdEP/SYlhRPqudPXxdA6yHeHfR4AdB0JUsjD4xoipx7DLbh2D6786wpXRBczcG8 5s3azrEQFV9+1NmTeJDPvWpnc1yLVMSmBHF9pX6hKGikx/keZ0Jp7qsnSZT+bQ== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 18 Nov 2025 17:13:22 +0100 Subject: [PATCH net v5 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: <20251118-ksz-fix-v5-1-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 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:33:25 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 5363D3730E1 for ; Tue, 18 Nov 2025 16:13:33 +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=1763482415; cv=none; b=ON/5GwwoK6qYYtQaLSBIN2UTpqP5SsMXzzLwjDmNDOOtyAVZg9A6lh8vKuZjl8y1K7XX2jCLun6DvDUddP7YaSLkG+kRJfPx6TBOoAcKO/24d5/j0k+DiP1u7czdEYbTw+C9kwa0WWIjQ+WP6D2nqHYyvfPOE9JajV6y3lbPCt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482415; c=relaxed/simple; bh=AEmkrFjqifoQnRxMtvLlTc3t/RLufAY+GpBg7zW6NZI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jitu0M1yarHo8N5rAW41tJgPTy0VNn7a5g2A8jEtuL++UMEkDUybQDpg/jPT26U0a8QhfLbrSRgTZj4hmTfgI1SbkL3J4qOFTqOQ1+8EFoWXxbzTRuqv/bDqWGi/tM3B/VZaRNxEAp40OT2ozurOWTvR2NW+ug2svCXFaZYmJBM= 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=B42aIL7x; 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="B42aIL7x" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C7972C10F57; Tue, 18 Nov 2025 16:13:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id EE6A6606FE; Tue, 18 Nov 2025 16:13:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F263C10371605; Tue, 18 Nov 2025 17:13:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763482411; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=PtjJwnZbSztJ0ylhjAx5WuFm6ywuzKa2m4FJNifI2/U=; b=B42aIL7xyojyioHuEIQM7P9blZcRUYLY3tIFmwjtpLaCFqOjHY2E2B5u5+fYcfstjgXJhZ OqXsQ1yZSugH9rPiIlydOj3uRMu3h/LO/2BuhEig/2P0V7C+rPDg9vdJbZhAeFZW850gO9 3AVJHiY6TTS+pUhREA6QK2mP840gmrDl8YkCfKS1seePHRYATunlM4THyAx57V+VzayXli tbFnKxo2WZGQCMT9BaQI9taCVW6iSPZp+UnFdGAqlWhOUsR58gE+jhK1N8DtlV+gENeI76 AnifmqtHAuSxPvVA34MWTLAF1AHVmtsOFHcdkN37F1Fp2AlRjk+9+mQtQ3sQ/g== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 18 Nov 2025 17:13:23 +0100 Subject: [PATCH net v5 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: <20251118-ksz-fix-v5-2-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 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:33:25 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 7C0A9377E8E; Tue, 18 Nov 2025 16:13:35 +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=1763482417; cv=none; b=QC4rX1xRSwZUk5mj59kKoKieIV++pDm7d30tMzGYhNWTfVruuObq9UEb+Go8gPT+DGHGsswXKkDaQkw4PAKf2g3/NUDCXhkSGHzLc4IInawpFwyq/zCopExYj+ZGJvTc+yyikjNNkncAslxmX87eW1/7lS2W/P1/2ZTAFuux5l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482417; 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=m29UI/hEoP11AonCrzlT13qntrhPvOjalO+eK05T7IeNdS5pl8FNOhKPN2JRrJR3mJ7Djj2G3tacFbLXX1C13tgS/tlcAnWY6SHZBGAxEYAIsWgZ0xNXG9SE+jPL1eAiS9xobJZfda0eb8tA3UnMoRr67HNbXxTxDM1hoGmoQkI= 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=OeXqGBIh; 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="OeXqGBIh" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id BF80F4E41760; Tue, 18 Nov 2025 16:13:33 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8DCD5606FE; Tue, 18 Nov 2025 16:13:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 6932E103713BD; Tue, 18 Nov 2025 17:13:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763482412; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=uxcBfrkPXkUZDJCua6/YvADKTChGewQXWcqnNL7MEe0=; b=OeXqGBIhdZxNA+eW+OsW2L1uhucZhCjnINSU7YwZNw2ln4iR58nCairvraJpTmV/z66+4k Rq8NJZXtzfuUgVrOETVeEf7YQbI4X+0PbsjtQGChRpnLisyeroJ//t5cIS8g8mBVe5usO2 v/t8D+ZzxSe6z74Ga9V2hRERQUXgzmWX+D/vOIeEXTDxZhMGQjZEGA3KrKjkF563NESI2Z js+X0Pt4GHIQ5ozzCMzJaJVkGeq/jXAlbEwaFao7nPzzrT3WZL5djG097DjHaSIP/GfM3y tytFShOLkCxL8CXJ0MHBYAMaT22DGLcTtIIu6zu0G9vXlg/fwoK+c4xjtiAEKA== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 18 Nov 2025 17:13:24 +0100 Subject: [PATCH net v5 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: <20251118-ksz-fix-v5-3-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 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:33:25 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 6DD5C393DD9; Tue, 18 Nov 2025 16:13:37 +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=1763482419; cv=none; b=C85D/4tlaEibg8v58bBIrj9r/eZu1P9GJYb37lACmgPGB7QeC2Sak5Xzxvs3sFq+0ev5hGBbuY1QG4L80eQ7uMROCMvigzZvN39QN6Ks+5Qt3XOq8bMnWu9OwHS7sOz8ysG+CSnzhVTKE6mSDA6OjPOq9p6jlYcCcVCF2alfzSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763482419; c=relaxed/simple; bh=JKG7ORh0GrfzPZKhd8BwrONka+21F0NTRO36+Y19Bl8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aGS39jP1VuuKG63pUSIulvDIIrEiO4AJJrWNc+hfETz6eFsJ/cpH6KscTYcVdutGjre6rVL4SB0QfZuDTfOyrOahNIEbQrHs35K43KWw15QqMRQgkOl08uOju4yzzsX4GKmABalpG7iI2xQOsXYGHsgzMe7yLLcCN/scn0mPc8o= 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=EaSM13NS; 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="EaSM13NS" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id C1EF51A1B91; Tue, 18 Nov 2025 16:13:35 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 978C9606FE; Tue, 18 Nov 2025 16:13:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1022A10371967; Tue, 18 Nov 2025 17:13:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763482414; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=DsPkhyYnMypR+gij9b9x1NWJrYAuKKcCEr8gfS22WWg=; b=EaSM13NSxzUSiw6oiO5BPK2xwe1DIumrnsWGakYdew/ovPOPu1R2oymUUHs4nKGmu4juCt BH8z2LdB8DJihf2rFU28N6memRw1fayopNYUiFCcvnP+vVUJYfEb1Om2/vUFj+Q3Gae2eB bAUwlVshqTJVXhXat+M09h76BbmXeTgE1KBUegaxI/YPp/ToStlIO3bXmwUlI3r03/szYD e2CNhrxv2aFZShXgZbeWpU4PaFQJM0w442VwaLP4zDyU41qyI6Q0CPWQ16HN9RNVtSbf/b OkX6TnPbMDdt2CBqQlp2/omGytu+QhifScX3pR2b+IHwrcbKEHW477Ya8cgZmA== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 18 Nov 2025 17:13:25 +0100 Subject: [PATCH net v5 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: <20251118-ksz-fix-v5-4-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 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_ptpirq, out_pirq and out_girq into a single label that releases all IRQ resources for all initialized ports. Free the port IRQ inside the initialization loop when ksz_ptp_irq_setup() fails, since the error path only iterates over the 'fully' initialized ports. 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 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 49827ac770e6fcc9e4a1a11e8814cdd90b17473e..1cb4f35edb49ba4f35ec3ae80fe= 1699d31540d96 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3036,12 +3036,14 @@ 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; + if (ret) { + ksz_irq_free(&dev->ports[dp->index].pirq); + goto port_release; + } } } } @@ -3051,7 +3053,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 +3076,15 @@ 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); 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:33:25 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