Skip to content

Commit a017b98

Browse files
bastien-curutchetgregkh
authored andcommitted
net: dsa: microchip: Free previously initialized ports on init failures
[ Upstream commit 0f80e21 ] 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: [email protected] Fixes: c9cd961 ("net: dsa: microchip: lan937x: add interrupt support for port phy link") Signed-off-by: Bastien Curutchet (Schneider Electric) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7f0bc8f commit a017b98

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,12 +2564,12 @@ static int ksz_setup(struct dsa_switch *ds)
25642564
dsa_switch_for_each_user_port(dp, dev->ds) {
25652565
ret = ksz_pirq_setup(dev, dp->index);
25662566
if (ret)
2567-
goto out_girq;
2567+
goto port_release;
25682568

25692569
if (dev->info->ptp_capable) {
25702570
ret = ksz_ptp_irq_setup(ds, dp->index);
25712571
if (ret)
2572-
goto out_pirq;
2572+
goto pirq_release;
25732573
}
25742574
}
25752575
}
@@ -2579,7 +2579,7 @@ static int ksz_setup(struct dsa_switch *ds)
25792579
if (ret) {
25802580
dev_err(dev->dev, "Failed to register PTP clock: %d\n",
25812581
ret);
2582-
goto out_ptpirq;
2582+
goto port_release;
25832583
}
25842584
}
25852585

@@ -2602,17 +2602,16 @@ static int ksz_setup(struct dsa_switch *ds)
26022602
out_ptp_clock_unregister:
26032603
if (dev->info->ptp_capable)
26042604
ksz_ptp_clock_unregister(ds);
2605-
out_ptpirq:
2606-
if (dev->irq > 0 && dev->info->ptp_capable)
2607-
dsa_switch_for_each_user_port(dp, dev->ds)
2608-
ksz_ptp_irq_free(ds, dp->index);
2609-
out_pirq:
2610-
if (dev->irq > 0)
2611-
dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds)
2605+
port_release:
2606+
if (dev->irq > 0) {
2607+
dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) {
2608+
if (dev->info->ptp_capable)
2609+
ksz_ptp_irq_free(ds, dp->index);
2610+
pirq_release:
26122611
ksz_irq_free(&dev->ports[dp->index].pirq);
2613-
out_girq:
2614-
if (dev->irq > 0)
2612+
}
26152613
ksz_irq_free(&dev->girq);
2614+
}
26162615

26172616
return ret;
26182617
}

0 commit comments

Comments
 (0)