Skip to contentSkip to conversation

clk: Make sure clk_init_data is fully initialized (part 1)

PATCH Applied Geert Uytterhoeven 11 participants 26 messages Aug 19 – Aug 21

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

cover clk: Make sure clk_init_data is fully initialized (part 1)

Hi all,

The clk_init_data structure contains three mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. When commit fc0c209c147f35ed ("clk: Allow parents to be specified without string names") added the last two methods, this was done in a backwards-compatible way, using a priority-based scheme:
- .name, .ops, .num_parents, and .flags must always be initialized,
- if .num_parents is non-zero, .parent_names must be initialized,
- if .parent_names is NULL, .parent_data must be initialized,
- if .parent_data is NULL, .parent_hws must be initialized and valid.

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 makes sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents.

This (small) series is part 1, and fixes all cases that I identified to be real bugs:
- The first patch fixes a crash I saw on BeagleBone Black,
- The other patches are only compile-tested.
All patches in this series can be applied independently.

Part 2 will be much larger (touching 185 files), and will fix the remaining cases that are currently harmless.

Thanks for your comments!

Geert Uytterhoeven (5):
clk: ti: Make sure clk_init_data is fully initialized
clk: visconti: Make sure clk_init_data is fully initialized
hwmon: (ltc4282) Make sure clk_init_data is fully initialized
iio: frequency: adf4377: Make sure clk_init_data is fully initialized
spi: amlogic-spisg: Make sure clk_init_data is fully initialized

 drivers/clk/ti/adpll.c          | 4 ++--
 drivers/clk/ti/divider.c        | 2 +-
 drivers/clk/ti/mux.c            | 2 +-
 drivers/clk/visconti/clkc.c     | 2 +-
 drivers/hwmon/ltc4282.c         | 2 +-
 drivers/iio/frequency/adf4377.c | 2 +-
 drivers/spi/spi-amlogic-spisg.c | 2 +-
 7 files changed, 8 insertions(+), 8 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/5 clk: ti: 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.

_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes 667f420c09f1417c ("clk: ti: mux: resolve parent clocks by DT index, not by name")
---
 drivers/clk/ti/adpll.c   | 4 ++--
 drivers/clk/ti/divider.c | 2 +-
 drivers/clk/ti/mux.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/clk/ti/adpll.c +2 -2
index e305fcbac6475b03..8885d28face50beb 100644
@@ -483,7 +483,7 @@ static const struct clk_ops ti_adpll_ops = {
 
 static int ti_adpll_init_dco(struct ti_adpll_data *d)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk *clock;
 	const char *postfix;
 	int width, err;
@@ -576,7 +576,7 @@ static int ti_adpll_init_clkout(struct ti_adpll_data *d,
 				struct clk *clk1)
 {
 	struct ti_adpll_clkout_data *co;
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk_ops *ops;
 	const char *parent_names[2];
 	const char *child_name;
drivers/clk/ti/divider.c +1 -1
index af923b8cb0ed8fbc..3b438c2d68aacd7c 100644
@@ -311,7 +311,7 @@ static struct clk *_register_divider(struct device_node *node,
 				     u32 flags,
 				     struct clk_omap_divider *div)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	const char *parent_name;
 	const char *name;
 
drivers/clk/ti/mux.c +1 -1
index ded4432f7528cc6e..0fef60e82107a5a5 100644
@@ -124,9 +124,9 @@ static struct clk *_register_mux(struct device_node *node, const char *name,
 				 struct clk_omap_reg *reg, u8 shift, u32 mask,
 				 s8 latch, u8 clk_mux_flags, u32 *table)
 {
+	struct clk_init_data init = {};
 	struct clk_omap_mux *mux;
 	struct clk *clk;
-	struct clk_init_data init;
 
 	/* allocate the mux */
 	mux = kzalloc_obj(*mux);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH treewide 1/5] clk: ti: Make sure clk_init_data is fully initialized

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

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.

_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 7 lines

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

Fixes 667f420c09f1417c ("clk: ti: mux: resolve parent clocks by DT index, not by name")

Sashiko has reviewed this patch and found no issues. It looks great!

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

Re: [PATCH treewide 1/5] clk: ti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 7 lines

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

Fixes 667f420c09f1417c ("clk: ti: mux: resolve parent clocks by DT index, not by name")
Reviewed-by on v1 1/5
#4 lore raw

Re: [PATCH treewide 1/5] clk: ti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 8 lines

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

Fixes 667f420c09f1417c ("clk: ti: mux: resolve parent clocks by DT index, not by name")

---

Thanks again for the fix.

maintainer Applied
#5 lore raw

Re: [PATCH treewide 1/5] clk: ti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven

Quoting Geert Uytterhoeven (2026-08-19 12:05:15)

Quoted 11 lines

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.

_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 8 lines

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

Fixes 667f420c09f1417c ("clk: ti: mux: resolve parent clocks by DT index, not by name")

---

Applied to clk-next

#6 lore raw

PATCH 2/5 clk: visconti: 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.

visconti_clk_register_gate() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes b4cbe606dc3674b2 ("clk: visconti: Add support common clock driver and reset driver")

---
Compile-tested only.

---
 drivers/clk/visconti/clkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/visconti/clkc.c +1 -1
index d0b193b5d0b35f94..4018d1298880dfbb 100644
@@ -81,9 +81,9 @@ static struct clk_hw *visconti_clk_register_gate(struct device *dev,
 						 u8	rs_idx,
 						 spinlock_t *lock)
 {
+	struct clk_init_data init = {};
 	struct visconti_clk_gate *gate;
 	struct clk_parent_data *pdata;
-	struct clk_init_data init;
 	struct clk_hw *hw;
 	int ret;
 
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH treewide 2/5] clk: visconti: 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] visconti_reset_status() incorrectly uses the bit index directly instead of a bitmask, resulting in corrupted status checks. --

--- Patch [2]: [PATCH treewide 2/5] clk: visconti: Make sure clk_init_data is fully initialized --- commit 61772ea3c610a3b3ebf435b199e400c1c5aaee4c
Author: Geert Uytterhoeven <[email protected]>

clk: visconti: 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. Not initializing all members may cause subtle issues when uninitialized members are unexpectedly accessed. This commit ensures all members are fully initialized to zero.

Quoted 5 lines
drivers/clk/visconti/clkc.c +0 -0
index d0b193b5d0b35..4018d1298880d 100644

drivers/clk/visconti/clkc.c static struct clk_hw *visconti_clk_register_gate(struct device *dev, · line 89

Quoted 10 lines
drivers/clk/visconti/clkc.c +1 -1
@@ -81,9 +81,9 @@ static struct clk_hw *visconti_clk_register_gate(struct device *dev,
 						 u8	rs_idx,
 						 spinlock_t *lock)
 {
+	struct clk_init_data init = {};
 	struct visconti_clk_gate *gate;
 	struct clk_parent_data *pdata;
-	struct clk_init_data init;
 	struct clk_hw *hw;
 	int ret;
 

[Severity: High]
This is a pre-existing issue, but while reviewing the visconti clock and reset driver changes, I noticed a potential problem with how rs_idx is used.

In drivers/clk/visconti/reset.c:visconti_reset_status():

	spin_lock_irqsave(reset->lock, flags);
	ret = regmap_read(reset->regmap, data->rson_offset, &reg);
	spin_unlock_irqrestore(reset->lock, flags);
	if (ret)
		return ret;

	return !(reg & data->rs_idx);

Is this reset status check operating as intended? Since rs_idx is a raw bit index (0-31), would it be more accurate to mask the register with BIT(data->rs_idx) rather than the raw index value?

Masking with the raw index seems like it could produce incorrect status returns. For example, if rs_idx is 0, the mask would always evaluate to 0.

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

Re: [PATCH treewide 2/5] clk: visconti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

visconti_clk_register_gate() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes b4cbe606dc3674b2 ("clk: visconti: Add support common clock driver and reset driver")
maintainer Reviewed-by on v1 2/5
#9 lore raw

RE: [PATCH treewide 2/5] clk: visconti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 34 lines

-----Original Message-----
From: Geert Uytterhoeven <[email protected]>
Sent: Thursday, August 20, 2026 4:05 AM
To: Tero Kristo <[email protected]>; Stephen Boyd <[email protected]>; Brian Masney <[email protected]>; Jerome Brunet <[email protected]>; iwamatsu nobuhiro(岩松 信洋 □DITC○C
PT) <[email protected]>; Nuno Sa <[email protected]>; Guenter Roeck <[email protected]>; Michael Hennerich <[email protected]>; Antoniu Miclaus <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Andy Shevchenko <[email protected]>; Sunny Luo <[email protected]>; Xianwei Zhao <[email protected]>; Mark Brown <[email protected]>; Kees Cook <[email protected]>; Kevin Hilman <[email protected]>; Mathieu Dubois-Briand <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Geert Uytterhoeven <[email protected]>
Subject: [PATCH treewide 2/5] clk: visconti: 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.

visconti_clk_register_gate() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 7 lines

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

Fixes b4cbe606dc3674b2 ("clk: visconti: Add support common clock driver

and reset driver")

Best regards,
Nobuhiro

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

maintainer Applied
#10 lore raw

Re: [PATCH treewide 2/5] clk: visconti: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven

Quoting Geert Uytterhoeven (2026-08-19 12:05:16)

Quoted 11 lines

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.

visconti_clk_register_gate() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 7 lines

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

Fixes b4cbe606dc3674b2 ("clk: visconti: Add support common clock driver and reset driver")

---

Applied to clk-next

#11 lore raw

PATCH 3/5 hwmon: (ltc4282) 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.

ltc428_clk_provider_setup() does not fill in any parent clocks, and assumes that init.num_parents is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes cbc29538dbf7d740 ("hwmon: Add driver for LTC4282")

---
Compile-tested only.

---
 drivers/hwmon/ltc4282.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ltc4282.c +1 -1
index b1675dc5b3c7fd2f..54ba4b8542e94b7b 100644
@@ -1106,7 +1106,7 @@ static const struct clk_ops ltc4282_ops = {
 static int ltc428_clk_provider_setup(struct ltc4282_state *st,
 				     struct device *dev)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_COMMON_CLK))
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH treewide 3/5] hwmon: (ltc4282) Make sure clk_init_data is fully initialized

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

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.

ltc428_clk_provider_setup() does not fill in any parent clocks, and assumes that init.num_parents is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes cbc29538dbf7d740 ("hwmon: Add driver for LTC4282")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Applied
#13 lore raw

Re: [PATCH treewide 3/5] hwmon: (ltc4282) Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

ltc428_clk_provider_setup() does not fill in any parent clocks, and assumes that init.num_parents is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes cbc29538dbf7d740 ("hwmon: Add driver for LTC4282")

Applied.

Thanks,
Guenter

Quoted 19 lines

---
Compile-tested only.

---
 drivers/hwmon/ltc4282.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ltc4282.c +1 -1
index b1675dc5b3c7fd2f..54ba4b8542e94b7b 100644
@@ -1106,7 +1106,7 @@ static const struct clk_ops ltc4282_ops = {
 static int ltc428_clk_provider_setup(struct ltc4282_state *st,
 				     struct device *dev)
 {
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_COMMON_CLK))
Reviewed-by on v1 3/5
#14 lore raw

Re: [PATCH treewide 3/5] hwmon: (ltc4282) Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

ltc428_clk_provider_setup() does not fill in any parent clocks, and assumes that init.num_parents is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes cbc29538dbf7d740 ("hwmon: Add driver for LTC4282")
#15 lore raw

PATCH 4/5 iio: frequency: adf4377: 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.

adf4377_clk_register() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes 60e5448ddbec2dc2 ("iio: frequency: adf4377: add clk provider support")

---
Compile-tested only.

---
 drivers/iio/frequency/adf4377.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/adf4377.c +1 -1
index 4dd19a9aa9943c57..f4eb9ba5878e1893 100644
@@ -990,7 +990,7 @@ static int adf4377_clk_register(struct adf4377_state *st)
 {
 	struct spi_device *spi = st->spi;
 	struct device *dev = &spi->dev;
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk_parent_data parent_data;
 	int ret;
 
Signature · 1 line
2.43.0
#16 lore raw

Re: [PATCH treewide 4/5] iio: frequency: adf4377: 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] Incomplete fix for uninitialized stack variables: struct clk_parent_data parent_data remains uninitialized on the stack, leading to a kernel crash during clock registration. --

--- Patch [4]: [PATCH treewide 4/5] iio: frequency: adf4377: Make sure clk_init_data is fully initialized --- commit 99e024a77f5bce5921d3c6b46054263aa450610d
Author: Geert Uytterhoeven <[email protected]>

iio: frequency: adf4377: Make sure clk_init_data is fully initialized

This commit initializes the clk_init_data structure in adf4377_clk_register() to zero. This prevents crashes caused by uninitialized fields like parent_names when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

drivers/iio/frequency/adf4377.c static int adf4377_clk_register(struct adf4377_state *st) · line 1003

Quoted 10 lines
drivers/iio/frequency/adf4377.c +1 -1
@@ -999,7 +999,7 @@ static int adf4377_clk_register(struct adf4377_state *st)
 {
 	struct spi_device *spi = st->spi;
 	struct device *dev = &spi->dev;
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk_parent_data parent_data;

[Severity: High]
This is a pre-existing issue, but does this struct clk_parent_data also need to be zero-initialized?

Only fw_name is explicitly assigned below, leaving name, hw, and index populated with stack garbage. When adf4377_clk_register() passes this to the clock framework, clk_core_populate_parent_map() will read parent_data.name and pass it to clk_cpy_name(), which ultimately calls strlen() and can cause a page fault during probe.

[ ... ]

Quoted 4 lines
drivers/iio/frequency/adf4377.c +0 -0
 	parent_data.fw_name = "ref_in";
 
drivers/iio/frequency/adf4377.c +0 -0
 	init.ops = &adf4377_clk_ops;
 	init.parent_data = &parent_data;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#17 lore raw

Re: [PATCH treewide 4/5] iio: frequency: adf4377: Make sure clk_init_data is fully initialized

Hi Sashiko,

Quoted 32 lines · On Wed, 19 Aug 2026 at 21:13, <[email protected]> wrote:

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

Pre-existing issues:
- [High] Incomplete fix for uninitialized stack variables: struct clk_parent_data parent_data remains uninitialized on the stack, leading to a kernel crash during clock registration. --

--- Patch [4]: [PATCH treewide 4/5] iio: frequency: adf4377: Make sure clk_init_data is fully initialized --- commit 99e024a77f5bce5921d3c6b46054263aa450610d
Author: Geert Uytterhoeven <[email protected]>

iio: frequency: adf4377: Make sure clk_init_data is fully initialized

This commit initializes the clk_init_data structure in adf4377_clk_register() to zero. This prevents crashes caused by uninitialized fields like parent_names when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.

drivers/iio/frequency/adf4377.c static int adf4377_clk_register(struct adf4377_state *st) · line 1003

Quoted 10 lines
drivers/iio/frequency/adf4377.c +1 -1
@@ -999,7 +999,7 @@ static int adf4377_clk_register(struct adf4377_state *st)
 {
      struct spi_device *spi = st->spi;
      struct device *dev = &spi->dev;
-     struct clk_init_data init;
+     struct clk_init_data init = {};
      struct clk_parent_data parent_data;

[Severity: High]
This is a pre-existing issue, but does this struct clk_parent_data also need to be zero-initialized?

Quoted 5 lines

Only fw_name is explicitly assigned below, leaving name, hw, and index populated with stack garbage. When adf4377_clk_register() passes this to the clock framework, clk_core_populate_parent_map() will read parent_data.name and pass it to clk_cpy_name(), which ultimately calls strlen() and can cause a page fault during probe.

Yes, parent_data has the same issue.
As Jonathan will rebase against rc1 anyway, I will send a v2. Thanks!

Quoted 10 lines

[ ... ]

Quoted 4 lines
      parent_data.fw_name = "ref_in";

      init.ops = &adf4377_clk_ops;
      init.parent_data = &parent_data;

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
Reviewed-by on v1 4/5
#18 lore raw

Re: [PATCH treewide 4/5] iio: frequency: adf4377: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

adf4377_clk_register() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes 60e5448ddbec2dc2 ("iio: frequency: adf4377: add clk provider support")
maintainer Applied
#19 lore raw

Re: [PATCH treewide 4/5] iio: frequency: adf4377: Make sure clk_init_data is fully initialized

Quoted 12 lines · On Wed, 19 Aug 2026 17:22:41 -0400 Brian Masney <[email protected]> wrote:
Quoted 11 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.

adf4377_clk_register() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 9 lines
Quoted 6 lines

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

Fixes 60e5448ddbec2dc2 ("iio: frequency: adf4377: add clk provider support")

Applied to the fixes-togreg branch of iio.git
I'll rebase on rc1 before sending a pull request (so waiting for that to be available)

Thanks,

Jonathan

#20 lore raw

PATCH 5/5 spi: amlogic-spisg: 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.

aml_spisg_clk_init() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes cef9991e04aed330 ("spi: Add Amlogic SPISG driver")

---
Compile-tested only.

---
 drivers/spi/spi-amlogic-spisg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-amlogic-spisg.c +1 -1
index afc8af04638d3b6e..9049a87e9d0f2df6 100644
@@ -636,7 +636,7 @@ static int aml_spisg_target_abort(struct spi_controller *ctlr)
 static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 {
 	struct device *dev = &spisg->pdev->dev;
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk_divider *div;
 	struct clk_div_table *tbl;
 	char name[32];
Signature · 1 line
2.43.0
#21 lore raw

Re: [PATCH treewide 5/5] spi: amlogic-spisg: Make sure clk_init_data is fully initialized

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

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

Pre-existing issues:
- [High] Severe imbalance in clock prepare/enable counts for pclk and core clocks, leading to negative enable counts and warnings during driver probe failure or removal.
- [High] Missing cleanup for runtime PM and sclk clock on the probe error path and module removal.
--

--- Patch [5]: [PATCH treewide 5/5] spi: amlogic-spisg: Make sure clk_init_data is fully initialized --- commit aa4fc6e665f6f8293335c8edd96584e8cdda40c6
Author: Geert Uytterhoeven <[email protected]>
Subject: spi: amlogic-spisg: 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.

Fixes cef9991e04aed330 ("spi: Add Amlogic SPISG driver")

drivers/spi/spi-amlogic-spisg.c static int aml_spisg_target_abort(struct spi_controller *ctlr) · line 642

Quoted 13 lines
drivers/spi/spi-amlogic-spisg.c +1 -1
index afc8af04638d3..9049a87e9d0f2 100644
@@ -636,7 +636,7 @@ static int aml_spisg_target_abort(struct spi_controller *ctlr)
 static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 {
 	struct device *dev = &spisg->pdev->dev;
-	struct clk_init_data init;
+	struct clk_init_data init = {};
 	struct clk_divider *div;
 	struct clk_div_table *tbl;
 	char name[32];

[Severity: High]
This is a pre-existing issue, but I noticed a severe imbalance in clock prepare/enable counts for the pclk and core clocks.

In aml_spisg_clk_init(), pclk is acquired with devm_clk_get_enabled():

	spisg->pclk = devm_clk_get_enabled(dev, "pclk");

But later in the same function, it is manually disabled:

	clk_disable_unprepare(spisg->pclk);

Since pclk is managed by devres, won't this manual disable unbalance the clock enable count right from the start?

This pattern is also repeated in the probe error path and remove functions:

drivers/spi/spi-amlogic-spisg.c:aml_spisg_probe() {
...
out_clk:

	if (spisg->core)
		clk_disable_unprepare(spisg->core);
	clk_disable_unprepare(spisg->pclk);

	return ret;
}

Does this cause double-disables and negative enable counts when the devres cleanup runs?

[Severity: High]
This is also a pre-existing issue, but I noticed missing cleanup for runtime PM and the sclk clock.

In aml_spisg_clk_init(), sclk is manually enabled:

	clk_prepare_enable(spisg->sclk);

And in aml_spisg_probe(), runtime PM is enabled:

	pm_runtime_enable(&spisg->pdev->dev);

However, if devm_request_irq() or spi_register_controller() fails, the out_clk error path simply returns:

drivers/spi/spi-amlogic-spisg.c:aml_spisg_probe() {
...
out_clk:

	if (spisg->core)
		clk_disable_unprepare(spisg->core);
	clk_disable_unprepare(spisg->pclk);

	return ret;
}

Doesn't this leak the sclk enable count and leave runtime PM enabled?

Additionally, aml_spisg_remove() also lacks a pm_runtime_disable() call and skips disabling sclk if the device is not runtime suspended. Should there be explicit teardowns for these in the error and removal paths?

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

Re: [PATCH treewide 5/5] spi: amlogic-spisg: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 11 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.

aml_spisg_clk_init() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

Quoted 6 lines

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

Fixes cef9991e04aed330 ("spi: Add Amlogic SPISG driver")
maintainer Reviewed-by on v1 5/5
#23 lore raw

Re: [PATCH treewide 5/5] spi: amlogic-spisg: Make sure clk_init_data is fully initialized

In reply to Geert Uytterhoeven
Quoted 36 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.

aml_spisg_clk_init() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.

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

Fixes cef9991e04aed330 ("spi: Add Amlogic SPISG driver")

---
Compile-tested only.

---
  drivers/spi/spi-amlogic-spisg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-amlogic-spisg.c +1 -1
index afc8af04638d3b6e..9049a87e9d0f2df6 100644
@@ -636,7 +636,7 @@ static int aml_spisg_target_abort(struct spi_controller *ctlr)
  static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
  {
         struct device *dev = &spisg->pdev->dev;
-       struct clk_init_data init;
+       struct clk_init_data init = {};
         struct clk_divider *div;
         struct clk_div_table *tbl;
         char name[32];
maintainer
#24 lore raw

Re: (subset) [PATCH treewide 0/5] clk: Make sure clk_init_data is fully initialized (part 1)

In reply to Geert Uytterhoeven
Quoted 16 lines · Geert Uytterhoeven

clk: Make sure clk_init_data is fully initialized (part 1)

Hi all,

The clk_init_data structure contains three mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. When commit fc0c209c147f35ed ("clk: Allow parents to be specified without string names") added the last two methods, this was done in a backwards-compatible way, using a priority-based scheme:
- .name, .ops, .num_parents, and .flags must always be initialized,
- if .num_parents is non-zero, .parent_names must be initialized,
- if .parent_names is NULL, .parent_data must be initialized,
- if .parent_data is NULL, .parent_hws must be initialized and valid.

Quoted 1 line

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.3

Thanks!

[5/5] spi: amlogic-spisg: Make sure clk_init_data is fully initialized

      https://git.kernel.org/broonie/spi/c/b2702908ee23

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#25 lore raw
In reply to Geert Uytterhoeven
Quoted 20 lines · Geert Uytterhoeven

The clk_init_data structure contains three mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. When commit fc0c209c147f35ed ("clk: Allow parents to be specified without string names") added the last two methods, this was done in a backwards-compatible way, using a priority-based scheme:
- .name, .ops, .num_parents, and .flags must always be initialized,
- if .num_parents is non-zero, .parent_names must be initialized,
- if .parent_names is NULL, .parent_data must be initialized,
- if .parent_data is NULL, .parent_hws must be initialized and valid.

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 makes sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents.

Quoted 8 lines

This (small) series is part 1, and fixes all cases that I identified to be real bugs:
- The first patch fixes a crash I saw on BeagleBone Black,
- The other patches are only compile-tested.
All patches in this series can be applied independently.

Part 2 will be much larger (touching 185 files), and will fix the remaining cases that are currently harmless.

FTR, I split part two in 13 subparts, per subsystem:
- "[PATCH 0/2] ARM/soc: Make sure clk_init_data is fully initialized"

    https://lore.kernel.org/[email protected]>
  - "[PATCH 0/3] ASoC: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH 00/45] clk: Make sure clk_init_data is fully initialized (part two)"
    https://lore.kernel.org/[email protected]>
  - "[PATCH 0/2] drm: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH] i2c: bcm2835: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/9f82f37e6d6c069cd44326bcd5e5a2a8069a13a9.1787239980.git.geert+renesas@glider.be>
  - "[PATCH 0/2] iio: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH 0/3] media: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH] MIPS: Alchemy: clock: Make sure clk_init_data is fully"
    https://lore.kernel.org/3610b51df642abb1fbb39f5bd93fddea43f8f164.1787240060.git.geert+renesas@glider.be>
  - "[PATCH 0/2] mmc: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH net-next 0/3] net: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH] peci: controller: aspeed: Make sure clk_init_data is fully"
    https://lore.kernel.org/48aa77c45e109f78ccd806bc3b7bf380c5bc5e71.1787240145.git.geert+renesas@glider.be>
  - "[PATCH 0/2] phy: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>
  - "[PATCH 0/5] rtc: Make sure clk_init_data is fully initialized"
    https://lore.kernel.org/[email protected]>

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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