Skip to contentSkip to conversation

net: Make sure clk_init_data is fully initialized

PATCH In review Geert Uytterhoeven 5 participants 10 messages Aug 21 – Aug 24

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover net: Make sure clk_init_data is fully initialized

Hi all,

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Hence this series aims to make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

Part One[1] fixed all cases that I identified to be real bugs, in response to a crash I saw on BeagleBone Black.

This series is the networking subpart of Part Two, which fixes remaining cases that are currently harmless. These are still fragile, and may cause future breakage when converting drivers to a different method for specifying the parents.

Thanks for your comments!

[1] "[PATCH treewide 0/5] clk: Make sure clk_init_data is fully initialized (part 1)"
https://lore.kernel.org/[email protected]

Geert Uytterhoeven (3):
net: macb: Make sure clk_init_data is fully initialized
net: mdio: mux-meson-g12a: Make sure clk_init_data is fully
initialized
net: phy: air_en8811h: Make sure clk_init_data is fully initialized

 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 drivers/net/mdio/mdio-mux-meson-g12a.c   | 2 +-
 drivers/net/phy/air_en8811h.c            | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
Signature · 12 lines
2.43.0

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
#1 lore raw

PATCH 1/3 net: macb: Make sure clk_init_data is fully initialized

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

---
Compile-tested only.

---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
index 1476bce77f34d2a5..319e43098f57ed7b 100644
@@ -5376,7 +5376,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,
 			       struct clk **hclk, struct clk **tx_clk,
 			       struct clk **rx_clk, struct clk **tsu_clk)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int err = 0;
 
 	err = macb_clk_init_dflt(pdev, pclk, hclk, tx_clk, rx_clk, tsu_clk);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH net-next 1/3] net: macb: Make sure clk_init_data is fully initialized

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The TX error recovery task modifies TX ring pointers and state without holding queue->tx_ptr_lock, racing with macb_start_xmit. --

--- Patch [1]: [PATCH net-next 1/3] net: macb: Make sure clk_init_data is fully initialized --- commit 72f05b5fbec22828f860396d626f5a6bbaacd336
Author: Geert Uytterhoeven <[email protected]>

net: macb: Make sure clk_init_data is fully initialized

This commit initializes the clk_init_data structure to prevent issues with uninitialized mutually-exclusive members when stack initialization patterns are enabled.

drivers/net/ethernet/cadence/macb_main.c

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 1476bce77f34d..319e43098f57e 100644

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a pre-existing data race between macb_tx_error_task() and macb_start_xmit() in this file.

Does macb_tx_error_task() race with macb_start_xmit() by modifying TX ring pointers without holding queue->tx_ptr_lock?

In macb_tx_error_task(), the ring pointers are reset without a lock:

    queue->tx_head = 0;
    queue->tx_tail = 0;

Concurrently, macb_start_xmit() acquires the lock and updates tx_head:

    spin_lock_irqsave(&queue->tx_ptr_lock, flags);

Since netif_tx_stop_all_queues() only marks the queue as stopped but does not wait for an already-executing ndo_start_xmit() to finish, could this race corrupt the software TX ring pointers?

This might lead to out-of-bounds DMA or use-after-free when the desynchronized ring is subsequently processed after a transmission error.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH net-next 1/3] net: macb: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven

Hello Geert,

Quoted 23 lines · Geert Uytterhoeven

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

---
Compile-tested only.

---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 1476bce77f34d2a5..319e43098f57ed7b 100644

drivers/net/ethernet/cadence/macb_main.c static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk, · line 5382

Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
@@ -5376,7 +5376,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,
 			       struct clk **hclk, struct clk **tx_clk,
 			       struct clk **rx_clk, struct clk **tsu_clk)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int err = 0;
 
 	err = macb_clk_init_dflt(pdev, pclk, hclk, tx_clk, rx_clk, tsu_clk);

I cannot give you a Tested-by because this triggers only on sifive,fu540-c000-gem compatible matching upstream devicetrees sifive/hifive-{unleashed,unmatched}-a00.dts

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#4 lore raw

PATCH 2/3 net: mdio: mux-meson-g12a: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

---
Compile-tested only.

---
 drivers/net/mdio/mdio-mux-meson-g12a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mdio/mdio-mux-meson-g12a.c +1 -1
index 08d6a6c93fb8bf02..e6c9ef3641afa27e 100644
@@ -223,7 +223,7 @@ static int g12a_ephy_glue_clk_register(struct device *dev)
 {
 	struct g12a_mdio_mux *priv = dev_get_drvdata(dev);
 	const char *parent_names[PLL_MUX_NUM_PARENT];
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct g12a_ephy_pll *pll;
 	struct clk_mux *mux;
 	struct clk *clk;
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH net-next 2/3] net: mdio: mux-meson-g12a: Make sure clk_init_data is fully initialized

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Busy-wait loop of up to 1 second with interrupts disabled in atomic clock enable callback --

--- Patch [2]: [PATCH net-next 2/3] net: mdio: mux-meson-g12a: Make sure clk_init_data is fully initialized --- commit 061a72e517f35ad4bc41a274d2b768db77d84ad1
Author: Geert Uytterhoeven <[email protected]>
Subject: net: mdio: mux-meson-g12a: Make sure clk_init_data is fully initialized

This commit ensures the clk_init_data structure is fully initialized by adding an empty initializer. This prevents subtle bugs related to mutually exclusive members when different stack initialization patterns are enabled.

drivers/net/mdio/mdio-mux-meson-g12a.c static int g12a_ephy_glue_clk_register(struct device *dev) · line 226

Quoted 9 lines
drivers/net/mdio/mdio-mux-meson-g12a.c +1 -1
@@ -223,7 +223,7 @@ static int g12a_ephy_glue_clk_register(struct device *dev)
 {
 	struct g12a_mdio_mux *priv = dev_get_drvdata(dev);
 	const char *parent_names[PLL_MUX_NUM_PARENT];
-	struct clk_init_data init;
+	struct clk_init_data init = {};

[Severity: High]
This is a pre-existing issue, but while reviewing this clock initialization, I noticed a potential lockup in the related PLL operations.

Does g12a_ephy_pll_enable() risk triggering the hard lockup detector?

The g12a_ephy_pll_ops struct is used later in this function to initialize the pll clock, and its .enable callback maps to g12a_ephy_pll_enable():

drivers/net/mdio/mdio-mux-meson-g12a.c:g12a_ephy_pll_enable() {
    ...
    return readl_poll_timeout(pll->base + ETH_PLL_CTL0, val,
                              val & PLL_CTL0_LOCK_DIG, 0, PLL_LOCK_TIMEOUT);
}

The clock framework calls the .enable callback with the enable_lock spinlock held and local interrupts disabled. Since the delay parameter is 0 and PLL_LOCK_TIMEOUT is 1,000,000, readl_poll_timeout() evaluates to a tight busy-wait loop.

If the PLL hardware fails to lock or takes a long time, could this stall the CPU for up to 1 second in an interrupt-disabled context?

Would it be possible to move this hardware initialization sequence to the .prepare callback instead, which executes in a preemptible context where sleeping delays are permitted?

Quoted 3 lines
drivers/net/mdio/mdio-mux-meson-g12a.c +0 -0
 	struct g12a_ephy_pll *pll;
 	struct clk_mux *mux;
 	struct clk *clk;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

PATCH 3/3 net: phy: air_en8811h: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

---
Compile-tested only.

---
 drivers/net/phy/air_en8811h.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/air_en8811h.c +2 -2
index edd49c193e476838..d1ab8744288bba0c 100644
@@ -932,7 +932,7 @@ static const struct clk_ops an8811hb_clk_ops = {
 
 static int an8811hb_clk_provider_setup(struct device *dev, struct clk_hw *hw)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_COMMON_CLK))
@@ -1031,7 +1031,7 @@ static const struct clk_ops en8811h_clk_ops = {
 
 static int en8811h_clk_provider_setup(struct device *dev, struct clk_hw *hw)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_COMMON_CLK))
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH net-next 3/3] net: phy: air_en8811h: Make sure clk_init_data is fully initialized

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The PHY driver calls the global clk_save_context() and clk_restore_context() APIs in its suspend and resume paths, forcefully saving and restoring all clocks in the entire system. --

--- Patch [3]: [PATCH net-next 3/3] net: phy: air_en8811h: Make sure clk_init_data is fully initialized --- commit 681a33786ef724d10dc7ce4f726e8ec894967ea4
Author: Geert Uytterhoeven <[email protected]>

net: phy: air_en8811h: Make sure clk_init_data is fully initialized

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues. This commit makes sure all members are fully initialized.

Quoted 4 lines
drivers/net/phy/air_en8811h.c +0 -0
index edd49c193e476..d1ab8744288bb 100644

[ ... ]

drivers/net/phy/air_en8811h.c static const struct clk_ops en8811h_clk_ops = { · line 1037

Quoted 9 lines
drivers/net/phy/air_en8811h.c +1 -1
@@ -1031,7 +1031,7 @@ static const struct clk_ops en8811h_clk_ops = {
 
 static int en8811h_clk_provider_setup(struct device *dev, struct clk_hw *hw)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_COMMON_CLK))

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this driver's clock handling I noticed a potential power management issue further down in the file.

In drivers/net/phy/air_en8811h.c:

static int en8811h_resume(struct phy_device *phydev)

{
	clk_restore_context();

	return genphy_resume(phydev);
}

static int en8811h_suspend(struct phy_device *phydev)

{
	clk_save_context();

	return genphy_suspend(phydev);
}

Is it safe for the PHY driver to call the global clk_save_context() and clk_restore_context() APIs during its suspend and resume handlers?

These APIs are intended for core PM operations and iterate over the entire system's clock tree to save or restore state for all clocks system-wide.

Could restoring all clocks globally whenever this single leaf PHY resumes forcefully reset or disrupt the clocks of completely unrelated devices, potentially causing system lockups or crashes?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer
#8 lore raw
In reply to Geert Uytterhoeven
Quoted 3 lines · On Fri, 21 Aug 2026 12:07:29 +0200 Geert Uytterhoeven wrote:
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 drivers/net/mdio/mdio-mux-meson-g12a.c   | 2 +-
 drivers/net/phy/air_en8811h.c            | 4 ++--

Hi Geert!

Unfortunately we don't queue -next patches during the merge window, you'll have to repsot.

Signature · 1 line
pw-bot: defer
Reviewed-by on the v1 series
#9 lore raw
In reply to Geert Uytterhoeven
Quoted 21 lines · Geert Uytterhoeven

Hi all,

The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

Hence this series aims to make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents.

Part One[1] fixed all cases that I identified to be real bugs, in response to a crash I saw on BeagleBone Black.

This series is the networking subpart of Part Two, which fixes remaining cases that are currently harmless. These are still fragile, and may cause future breakage when converting drivers to a different method for specifying the parents.

Quoted 5 lines

Thanks for your comments!

[1] "[PATCH treewide 0/5] clk: Make sure clk_init_data is fully initialized (part 1)"
https://lore.kernel.org/[email protected]

For the series: