FAILED: patch "[PATCH] net: dsa: microchip: Free previously initialized ports on" failed to apply to 6.12-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 0f80e21bf6229637e193248fbd284c0ec44bc0fd
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025120246-talcum-rectangle-f99d@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 0f80e21bf6229637e193248fbd284c0ec44bc0fd Mon Sep 17 00:00:00 2001
From: "Bastien Curutchet (Schneider Electric)" <[email protected]>
Date: Thu, 20 Nov 2025 10:12:03 +0100
Subject: [PATCH] net: dsa: microchip: Free previously initialized ports on
init failures
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.
drivers/net/dsa/microchip/ksz_common.c +11 -12
@@ -3038,12 +3038,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; } } }
@@ -3053,7 +3053,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; } }
@@ -3076,17 +3076,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; }
Sasha Levin
maintainerPATCH 1/3 net: dsa: microchip: Do not execute PTP driver code for unsupported switches
From: Tristram Ha <[email protected]>
[ Upstream commit 6ed3472173c575cd8aaed6c62eb74f7728404ee6 ]
The PTP driver code only works for certain KSZ switches like KSZ9477, KSZ9567, LAN937X and their varieties. This code is enabled by kernel configuration CONFIG_NET_DSA_MICROCHIP_KSZ_PTP. As the DSA driver is common to work with all KSZ switches this PTP code is not appropriate for other unsupported switches. The ptp_capable indication is added to the chip data structure to signal whether to execute those code.
Stable-dep-of: 0f80e21bf622 ("net: dsa: microchip: Free previously initialized ports on init failures")
--- drivers/net/dsa/microchip/ksz_common.c | 40 +++++++++++++++++++------- drivers/net/dsa/microchip/ksz_common.h | 1 + 2 files changed, 30 insertions(+), 11 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +29 -11
@@ -1342,6 +1342,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rgmii = {false, false, true}, .internal_phy = {true, true, false}, .gbit_capable = {false, false, true}, + .ptp_capable = true, .wr_table = &ksz8563_register_set, .rd_table = &ksz8563_register_set, },
@@ -1553,6 +1554,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, true, false, false}, .gbit_capable = {true, true, true, true, true, true, true}, + .ptp_capable = true, .wr_table = &ksz9477_register_set, .rd_table = &ksz9477_register_set, },
@@ -1680,6 +1682,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rgmii = {false, false, true}, .internal_phy = {true, true, false}, .gbit_capable = {true, true, true}, + .ptp_capable = true, }, [KSZ8567] = {
@@ -1715,6 +1718,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, false, false}, .gbit_capable = {false, false, false, false, false, true, true}, + .ptp_capable = true, }, [KSZ9567] = {
@@ -1747,6 +1751,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, true, false, false}, .gbit_capable = {true, true, true, true, true, true, true}, + .ptp_capable = true, }, [LAN9370] = {
@@ -1775,6 +1780,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rmii = {false, false, false, false, true}, .supports_rgmii = {false, false, false, false, true}, .internal_phy = {true, true, true, true, false}, + .ptp_capable = true, }, [LAN9371] = {
@@ -1803,6 +1809,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rmii = {false, false, false, false, true, true}, .supports_rgmii = {false, false, false, false, true, true}, .internal_phy = {true, true, true, true, false, false}, + .ptp_capable = true, }, [LAN9372] = {
@@ -1835,6 +1842,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, true, false, false}, .internal_phy = {true, true, true, true, false, false, true, true}, + .ptp_capable = true, }, [LAN9373] = {
@@ -1867,6 +1875,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, true, false, false}, .internal_phy = {true, true, true, false, false, false, true, true}, + .ptp_capable = true, }, [LAN9374] = {
@@ -1899,6 +1908,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, true, false, false}, .internal_phy = {true, true, true, true, false, false, true, true}, + .ptp_capable = true, }, };EXPORT_SYMBOL_GPL (ksz_switch_chips);
@@ -2556,16 +2566,21 @@ static int ksz_setup(struct dsa_switch *ds)if (ret) goto out_girq; - ret =ksz_ptp_irq_setup (ds, dp->index); -if (ret) - goto out_pirq; +if (dev->info->ptp_capable) { + ret =ksz_ptp_irq_setup (ds, dp->index); +if (ret) + goto out_pirq; + } } } - ret =ksz_ptp_clock_register (ds); -if (ret) { -dev_err (dev->dev,"Failed to register PTP clock: %d\n" , ret); - goto out_ptpirq; +if (dev->info->ptp_capable) { + ret =ksz_ptp_clock_register (ds); +if (ret) { +dev_err (dev->dev,"Failed to register PTP clock: %d\n" , + ret); + goto out_ptpirq; + } } ret =ksz_mdio_register (dev);
@@ -2585,9 +2600,10 @@ static int ksz_setup(struct dsa_switch *ds)return 0 ; out_ptp_clock_unregister: -ksz_ptp_clock_unregister (ds); +if (dev->info->ptp_capable) +ksz_ptp_clock_unregister (ds); out_ptpirq: -if (dev->irq >0 ) +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:
@@ -2606,11 +2622,13 @@ static void ksz_teardown(struct dsa_switch *ds)struct ksz_device *dev = ds->priv;struct dsa_port *dp; -ksz_ptp_clock_unregister (ds); +if (dev->info->ptp_capable) +ksz_ptp_clock_unregister (ds);if (dev->irq >0 ) {dsa_switch_for_each_user_port (dp, dev->ds) { -ksz_ptp_irq_free (ds, dp->index); +if (dev->info->ptp_capable) +ksz_ptp_irq_free (ds, dp->index);ksz_irq_free (&dev->ports[dp->index].pirq); }
drivers/net/dsa/microchip/ksz_common.h +1 -0
@@ -86,6 +86,7 @@ struct ksz_chip_data {bool supports_rgmii[KSZ_MAX_NUM_PORTS ];bool internal_phy[KSZ_MAX_NUM_PORTS ];bool gbit_capable[KSZ_MAX_NUM_PORTS ]; +bool ptp_capable;const struct regmap_access_table *wr_table;const struct regmap_access_table *rd_table; };
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/3 net: dsa: microchip: Don't free uninitialized ksz_irq
From: "Bastien Curutchet (Schneider Electric)" <[email protected]>
[ Upstream commit 25b62cc5b22c45face094ae3e8717258e46d1d19 ]
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.
Use dsa_switch_for_each_user_port_continue_reverse() in the error path to iterate only over the fully initialized ports.
Stable-dep-of: 0f80e21bf622 ("net: dsa: microchip: Free previously initialized ports on init failures")
--- drivers/net/dsa/microchip/ksz_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.c +1 -1
@@ -2608,7 +2608,7 @@ static int ksz_setup(struct dsa_switch *ds)ksz_ptp_irq_free (ds, dp->index); out_pirq:if (dev->irq >0 ) -dsa_switch_for_each_user_port (dp, dev->ds) +dsa_switch_for_each_user_port_continue_reverse (dp, dev->ds)ksz_irq_free (&dev->ports[dp->index].pirq); out_girq:if (dev->irq >0 )
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 3/3 net: dsa: microchip: Free previously initialized ports on init failures
In reply to Sasha LevinFrom: "Bastien Curutchet (Schneider Electric)" <[email protected]>
[ 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.
--- drivers/net/dsa/microchip/ksz_common.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +11 -12
@@ -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; }
Signature · 1 line
2.51.0