]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: dsa: microchip: Free previously initialized ports on init failures
authorBastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
Tue, 2 Dec 2025 19:21:00 +0000 (14:21 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Dec 2025 21:25:03 +0000 (06:25 +0900)
[ Upstream commit 0f80e21bf6229637e193248fbd284c0ec44bc0fd ]

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 for port phy link")
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
Link: https://patch.msgid.link/20251120-ksz-fix-v6-4-891f80ae7f8f@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/dsa/microchip/ksz_common.c

index 010f267abe90275866d5a43dede850da19149a2f..ff47c7cfc582b91d04dbff5f9e6b6a6842fcb1a0 100644 (file)
@@ -2564,12 +2564,12 @@ static int ksz_setup(struct dsa_switch *ds)
                dsa_switch_for_each_user_port(dp, dev->ds) {
                        ret = ksz_pirq_setup(dev, dp->index);
                        if (ret)
-                               goto out_girq;
+                               goto port_release;
 
                        if (dev->info->ptp_capable) {
                                ret = ksz_ptp_irq_setup(ds, dp->index);
                                if (ret)
-                                       goto out_pirq;
+                                       goto pirq_release;
                        }
                }
        }
@@ -2579,7 +2579,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;
                }
        }
 
@@ -2602,17 +2602,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);
+       }
 
        return ret;
 }