Skip to content

Commit e7e8e9b

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: stable@vger.kernel.org Fixes: c9cd961 ("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> [ replaced dsa_switch_for_each_user_port_continue_reverse() macro with dsa_switch_for_each_port_continue_reverse() plus manual dsa_port_is_user() check ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3b5a611 commit e7e8e9b

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,18 +2163,18 @@ static int ksz_setup(struct dsa_switch *ds)
21632163
dsa_switch_for_each_user_port(dp, dev->ds) {
21642164
ret = ksz_pirq_setup(dev, dp->index);
21652165
if (ret)
2166-
goto out_girq;
2166+
goto port_release;
21672167

21682168
ret = ksz_ptp_irq_setup(ds, dp->index);
21692169
if (ret)
2170-
goto out_pirq;
2170+
goto pirq_release;
21712171
}
21722172
}
21732173

21742174
ret = ksz_ptp_clock_register(ds);
21752175
if (ret) {
21762176
dev_err(dev->dev, "Failed to register PTP clock: %d\n", ret);
2177-
goto out_ptpirq;
2177+
goto port_release;
21782178
}
21792179

21802180
ret = ksz_mdio_register(dev);
@@ -2191,17 +2191,17 @@ static int ksz_setup(struct dsa_switch *ds)
21912191

21922192
out_ptp_clock_unregister:
21932193
ksz_ptp_clock_unregister(ds);
2194-
out_ptpirq:
2195-
if (dev->irq > 0)
2196-
dsa_switch_for_each_user_port(dp, dev->ds)
2194+
port_release:
2195+
if (dev->irq > 0) {
2196+
dsa_switch_for_each_port_continue_reverse(dp, dev->ds) {
2197+
if (!dsa_port_is_user(dp))
2198+
continue;
21972199
ksz_ptp_irq_free(ds, dp->index);
2198-
out_pirq:
2199-
if (dev->irq > 0)
2200-
dsa_switch_for_each_user_port(dp, dev->ds)
2200+
pirq_release:
22012201
ksz_irq_free(&dev->ports[dp->index].pirq);
2202-
out_girq:
2203-
if (dev->irq > 0)
2202+
}
22042203
ksz_irq_free(&dev->girq);
2204+
}
22052205

22062206
return ret;
22072207
}

0 commit comments

Comments
 (0)