[PATCH net v2 1/4] net: dsa: microchip: common: Fix checks on irq_find_mapping()

Bastien Curutchet (Schneider Electric) posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH net v2 1/4] net: dsa: microchip: common: Fix checks on irq_find_mapping()
Posted by Bastien Curutchet (Schneider Electric) 1 month, 1 week ago
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: ff319a644829 ("net: dsa: microchip: move interrupt handling logic from lan937x to ksz_common")
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
---
 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/microchip/ksz_common.c
index a962055bfdbd8fbfc135b2dec73c222a213985c4..3a4516d32aa5f99109853ed400e64f8f7e2d8016 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)
 
 			irq = irq_find_mapping(dev->ports[port].pirq.domain,
 					       PORT_SRC_PHY_INT);
-			if (irq < 0) {
-				ret = irq;
+			if (!irq) {
+				ret = -EINVAL;
 				goto out;
 			}
 			ds->user_mii_bus->irq[phy] = 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);
 
 	pirq->irq_num = irq_find_mapping(dev->girq.domain, p);
-	if (pirq->irq_num < 0)
-		return pirq->irq_num;
+	if (!pirq->irq_num)
+		return -EINVAL;
 
 	return ksz_irq_common_setup(dev, pirq);
 }

-- 
2.51.0
Re: [PATCH net v2 1/4] net: dsa: microchip: common: Fix checks on irq_find_mapping()
Posted by Jakub Kicinski 1 month, 1 week ago
On Thu, 06 Nov 2025 13:53:08 +0100 Bastien Curutchet (Schneider
Electric) wrote:
> Fixes: ff319a644829 ("net: dsa: microchip: move interrupt handling logic from lan937x to ksz_common")

This commit just moves the buggy code around, the fixes tag should
point at the commit which introduced the buggy code (first commit
in which the bug could be reproduced). I think other commits suffer
from a similar issue. Please look a little deeper into the history.
-- 
pw-bot:  cr
Re: [PATCH net v2 1/4] net: dsa: microchip: common: Fix checks on irq_find_mapping()
Posted by Bastien Curutchet 1 month, 1 week ago
Hi Jakub,

On 11/11/25 3:27 AM, Jakub Kicinski wrote:
> On Thu, 06 Nov 2025 13:53:08 +0100 Bastien Curutchet (Schneider
> Electric) wrote:
>> Fixes: ff319a644829 ("net: dsa: microchip: move interrupt handling logic from lan937x to ksz_common")
> 
> This commit just moves the buggy code around, the fixes tag should
> point at the commit which introduced the buggy code (first commit
> in which the bug could be reproduced). I think other commits suffer
> from a similar issue. Please look a little deeper into the history.

Sorry about this, I'll take a closer look to find the relevant buggy commit.

Best regards,
Bastien