From nobody Tue Dec 2 02:51:11 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 80A1F32E6AB; Mon, 17 Nov 2025 13:06:05 +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=1763384767; cv=none; b=X/8DELWW0hyZ88YC6xEQnYtwZuOhiAUzixngVv5E8f0/jcwIn3cQRafVaQRpRzHtnnmyVMMO834e3enYUj00enzT3ZHN1czQTiXRCH8MfcgeBF/yGzOR0sItuqPU9iTqA82v6mbLVHkDw5lZb5lv/b7T0c9zBQwf+Xm8uGgC+n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763384767; c=relaxed/simple; bh=Z+tuxarBHcRf03hexaRUPHmiKA1sZNeRDUlTYTEkTIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aPT8VkDI/IfdoyUHIoAhe9QoOBCm4ZXUpD0FEQkk23b7oMvHlpClk8Eo59u4v3+tMCwC/zkORW7dSKqt5j7cyiPk75mzP9KWvfZAHv0ovoelMCzzn3MWlmF6jnj8Xp/erocE/1gCiUGP/Zdgw96hz9QgdpUUrTNjvadAG6mvU8Q= 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=tTbcMzAI; 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="tTbcMzAI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id C382A1A1B79; Mon, 17 Nov 2025 13:06:03 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 997B5606B9; Mon, 17 Nov 2025 13:06:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 74CB010371D32; Mon, 17 Nov 2025 14:06:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763384762; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=CvnWrT3thpWNlYlyOwUMzAwg6Afa8Xa8RrmUZcVmlZ8=; b=tTbcMzAIimDwj+5GmnWQtvaBulYfZ9JtQsE43Pdod3tbZDWueebeSDP0/npF1pvDkzas6E LPeqCPKQk9AQ5QFXlKivaphtVC9yKF1JQhNy1bJGToNmhk2gWj8YVx1zc/9rlYQavkAo0w U05+Os/E9jsdYD/E7MbSEKoSFbh48oOxvbHsOVrgE3ng6nfgGjikhOv/lCsQyVOHnJ5x9b xejMZMQWofjDingQTCt6GYwmeWFD2vbkJnM0mflTF2eP9QSiGD47TKyB0iF2n1RCzbeF8J hyz1igeZFbyIBIqg75S1qPs7Vcw+fWVTuAl5ZFT7BIJcfBT3I8gEECGkGtljTw== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 17 Nov 2025 14:05:42 +0100 Subject: [PATCH net v4 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: <20251117-ksz-fix-v4-1-13e1da58a492@bootlin.com> References: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com> In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@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)" 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. 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 2251ab23859b93a4f8af30a7d9c209ca64121408..c724f5af5d98bf3ff784e36393d= d5b3fa7b37c13 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2584,8 +2584,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; @@ -2949,8 +2949,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:51:11 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 45BEC1DF27D for ; Mon, 17 Nov 2025 13:06:06 +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=1763384769; cv=none; b=Z8VCwyeY7OasCUqMg1ZnH8aUYZlkr2uwd9Otal4E9/NELHeYt05y9jU8ctsYSHo/H6txZgAos17qXIv+TaYJdyMoMwHrUwmg8/rFQyrkWJvO1nEvJx8+5f/ByOoFMBL4oreO2uOaE70DnwSv2OB/HHIB1/Tx0T5urvOa2Ucbtf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763384769; c=relaxed/simple; bh=dtd0+nF+bp/Pfk/d35cPc0tB+EATqNkUgd8y1OCFLQI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BdWnHbfHcpXMVcnr5Ky7kY9/G+KcIM2fgAO5qN2v39mmDvkW++mQNi+gIq2UhcWIU1ujAQznsuQ2yPfhgvjBJ2H58TUZlaOEggKBgI7NhDhtmPuj/aAD+PqvkDXc1FTX2/a77V3sFCQK7RuOj006yyAEkpEwrJDhuqVnoRN0hoA= 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=F0S1WWiS; 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="F0S1WWiS" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 6E6D71A1B7A; Mon, 17 Nov 2025 13:06:05 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 43A0D606B9; Mon, 17 Nov 2025 13:06:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 168D310371C1B; Mon, 17 Nov 2025 14:06:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763384764; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=dwsKotiDEJnhW0UR2k6JPDo93YR2yL0iASSN9Mxocl0=; b=F0S1WWiSxYq0ajYh4BY6fctSMuRPpLkAKAQucYCY3NX4tuh+wqCA33EV86iKwggVwVH15T iedFB9vdLgvZdB4SjAaecM9GAwc2c2ms0xoUdziEq4zilSaBr0q1wJRmGetrqDIgnwY95f Dnv60NoX7myqq9TH2weDpDZ/BwFOl52DPltNFY3S0S0QFV7Gqcmvz++EoA3XuNbpMAG9qG SvYNsQ5cNCl4srPwLmOPXgDDgOVaV2N1UEUs7AePcfYAz1d7E821yw/Xotxcr8MkI6fDvB 2o77gRDumERUPAQpt6tzqH9n+i8YKQK8jNhaY/0CResb+/wgS2zLBqDFAu6jxA== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 17 Nov 2025 14:05:43 +0100 Subject: [PATCH net v4 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: <20251117-ksz-fix-v4-2-13e1da58a492@bootlin.com> References: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com> In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@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)" 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. 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:51:11 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 211272D3A6A for ; Mon, 17 Nov 2025 13:06:08 +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=1763384771; cv=none; b=t5dfx9PZI12t4+fEkUeVttVgOb8rlQu82UtwH4e7w3VL95j8ddWsB6Jpxbc4C8lMP91heQ/MaiviPi5UGdXsJ88Lp0P63a51sFFmeegXeQyn2nBADDxwXDGkcXN3G1w/OF3mlB5DAip8yh7oLk1UwpTa8QnAlsa0dCx5P09GShg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763384771; c=relaxed/simple; bh=4r/7XxgCCqAeVsQLUFOd77vszd2iOYLjLQs4R+5In7c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ert0+YybnbRAuudprZZ5xNncj1ZUdnfby1Scn3l6B3cidjFs5dIiyQ6n12uobhM72mF5UlSr/iRtJWRjTEGys+hZVXHANxErydjaEmzEyqI1iu7zU7kAsGWfJHZ+BhB/2CPGGbZTssXBfrQuMnDaid9yMcLZyWH9OazTwA4FDRM= 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=dHBg8iqv; 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="dHBg8iqv" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 0F74A1A1B77; Mon, 17 Nov 2025 13:06:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CE30E606B9; Mon, 17 Nov 2025 13:06:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B88D610371D37; Mon, 17 Nov 2025 14:06:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763384766; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=iJC44dVU5yEb8hqqRuBXRUyct/KJL5rrWwNwUJgQGhI=; b=dHBg8iqvDHYQS1AKjR9b5BSpE+mKD/cMAuCDVAOVnaWgR8sFSlHLlBk+gj52vPJDT4LwvR 1xDBTQULp/QL1x8XsKvoSlvUU91IVn9vR/YytMIY++zqDeLAq1c8qFWzWrBkOHpyhViDez tAAkhPg5WPaqb4xYEfuTxgjsSOzPtKTVe1Hi5mI/YNR34xMTRS2AQ1oI6aShlxKmlbXCIh wfch72+0A8XuLLuqpFxTKIYrXcICBZ+ATDZ+doRR3iguKRQ92pcU9w/ttDSgPz2WFHlux9 Bk90WTR4jC+L3mgoyJe93mS+s6fUvtqPueqyEav6SbfMq1kWFXMXXmQh2Re1Bg== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 17 Nov 2025 14:05:44 +0100 Subject: [PATCH net v4 3/5] 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: <20251117-ksz-fix-v4-3-13e1da58a492@bootlin.com> References: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com> In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@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)" 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. Ensure that the ksz_irq is initialized before calling ksz_irq_free(). Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timest= amping") Signed-off-by: Bastien Curutchet (Schneider Electric) -- Regarding the Fixes tag here, IMO before cc13ab18b201 it was safe to not check the domain and the IRQ number because I don't see any path where ksz_irq_free() would be called on a non-initialized ksz_irq --- drivers/net/dsa/microchip/ksz_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index c724f5af5d98bf3ff784e36393dd5b3fa7b37c13..a622416d966330187ee062b2f44= 051ddf4ce2a78 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3078,9 +3078,12 @@ static int ksz_setup(struct dsa_switch *ds) 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(dp, dev->ds) - ksz_irq_free(&dev->ports[dp->index].pirq); + if (dev->irq > 0) { + dsa_switch_for_each_user_port(dp, dev->ds) { + if (dev->ports[dp->index].pirq.domain) + ksz_irq_free(&dev->ports[dp->index].pirq); + } + } out_girq: if (dev->irq > 0) ksz_irq_free(&dev->girq); --=20 2.51.1 From nobody Tue Dec 2 02:51:11 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 B1F0D32F75F; Mon, 17 Nov 2025 13:06:10 +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=1763384772; cv=none; b=e+FGw8AuSunZD9tqTHSWVVaAcUR2t14Qm81x1wn33BikzJkoqVeFLrOb2PeSLqUyREVIB5Vk78adDuJrngdaV7WNEMePU78zTLGPyDxsc3POp9A/g+zslU5vYYzDYlz7Iks5XUCZgJ2mtvTcWov/6wQNQtsqd2yObaloq0+8B0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763384772; c=relaxed/simple; bh=u54h61ZvJrTztE7sbN5g3tlZG3G0RPTsAXhQ2w682FM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tzh6fWmNFkuc02ryrxwx6p9JHZce4QIY34u4tK9CxWE+vOXbzQBhlt3eC2vmSDPN5urBGE6MrQ5J5TNUncWG6va/eugftwQi8ngU3ciD7+qkb/OZ/F8zPNqQuRAGqVd1DJ5Q9Utl9r9lIXXU3JoyUAd4qGn9useFKHwPZZm3bOM= 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=HRZuz9nk; 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="HRZuz9nk" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id D038A4E4173F; Mon, 17 Nov 2025 13:06:08 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A5418606B9; Mon, 17 Nov 2025 13:06:08 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5EB291037160D; Mon, 17 Nov 2025 14:06:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763384767; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=yrH8+DZYQiftysCPablq1ZjCFXzIN4d8ug9Dmz4QpHo=; b=HRZuz9nkWXGwMam2grpnYWcrekez2QSXioIY5vWVBFSJJYrAA6lDz+TLXerPpLDU3rFXjE 8Gqg+AL+n3Ij2ucvSCJnA9WCu4Xoju/CeolkcMZEBks0YVHelKCwTw0teXEdIXHg6LkT+H cHaAaG5NZip0ND6dcHkqdyKA+4v/DDneGJlgayf92anZQYI093pId1pZwP460mJ/HAzA7F oa6pXD13Mobkiq3F56izAi9VeSjZ2Yj+95847QDbQ7RkLkxgRehYuZ+71AXmM6XXEHSrop 33oYKTjj3eFcwYS+amMtICXwjfR9GQyTGHNhitpwxRunWywW8MtZZoJ5qFO2ag== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 17 Nov 2025 14:05:45 +0100 Subject: [PATCH net v4 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: <20251117-ksz-fix-v4-4-13e1da58a492@bootlin.com> References: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com> In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@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)" X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 If ksz_pirq_setup() fails after at least one successful port initialization, the goto jumps directly to the global irq freeing, leaking the resources of the previously initialized ports. Fix the goto jump to release all the potentially initialized ports. Remove the no-longer used out_girq label. 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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index a622416d966330187ee062b2f44051ddf4ce2a78..2b6f7abea00776fafff0c1774ca= b297a7ef261da 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3035,7 +3035,7 @@ 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 out_pirq; =20 if (dev->info->ptp_capable) { ret =3D ksz_ptp_irq_setup(ds, dp->index); @@ -3083,10 +3083,8 @@ static int ksz_setup(struct dsa_switch *ds) if (dev->ports[dp->index].pirq.domain) 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:51:11 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 819CA330310; Mon, 17 Nov 2025 13:06:11 +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=1763384773; cv=none; b=K2WI4rbuaoQcMtef5x6apC7ChbL+tSlPiWdufOQrbSBqzlMSwtXeu+XALmjV118RqB4jYsZD2he3bbogNUYoNgk+NGgV3U0PsaazDg1hzZwOveasl5skLFQeKfxVsWsVPzsx+rDfzRwRFmiaktE6FAzL8nvFqfGPlMOD2y5mALE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763384773; c=relaxed/simple; bh=NbHYLAKKQwa4KzZkf1P/zULSvm3EvEdc+odVrrzzWyI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RVJU+tK6gjQdX55JpttJeJW1VVDDcR8i6ToqzjpN3x+jjXkbNLOBoe86j4B682BR1kqehPs8cBHh0xL/rFtKVmRUjAg1u5srF9/Mis3LueEqW/KFZ/0wYpQc0tQEJr7pChZL2Gphuj0oC19Gy9whXF96K31axZhNoVURRqmRG5M= 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=QdInBhNh; 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="QdInBhNh" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 04FE2C12654; Mon, 17 Nov 2025 13: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 162FA606B9; Mon, 17 Nov 2025 13:06:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2044E10371C1B; Mon, 17 Nov 2025 14:06:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763384769; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=OpB1gDU0nCBuRVYBN5PzLrnf5KEGlk2ZTpPPBE+o0sk=; b=QdInBhNhNE/O4E2eTxS7nnpB9Zep/pSIGvC4zOe3TB08s/0hZbh8J1ZAi3GH8xa4PuGN13 DiG+cybFVcIMU5GESfe7i9nNP8KdTxfG5hm6fgEs7wDDXxDuTUFUl8T139RnWV9P9tPL9r KCe56jN/GOQ8yT4Qj4sqDHJkmEODKI3C3BbcVzYq1hLMLTPcUlVjfsZJh8iyE9OsuwY/Mj HGVI0N/ysZPC/ClcU6g350msJwelMCZMgQnbI10pXAAo57CXHQTmHZ9bpg9dJ0JMh2B+FQ RpbQ4zPmh/ouhFkDKFC0mjAjaTwU5JeT8aCO9Rh1BcRe1D3hg1BUe9oSbkQoxg== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 17 Nov 2025 14:05:46 +0100 Subject: [PATCH net v4 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: <20251117-ksz-fix-v4-5-13e1da58a492@bootlin.com> References: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com> In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@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)" 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. Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timest= amping") 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