Skip to contentSkip to conversation

clk: fix crash on clk_set_rate clean rate cache

PATCH RESEND In review Christian Marangi 4 participants 8 messages Mar 15, 2025 – Apr 30, 2025 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 clk: fix crash on clk_set_rate clean rate cache

It's currently possible to make the bootloader crash on calling clk_set_rate caused by the loop in clk_clean_rate_cache.

The loop assume that every child of the clock node are also clock device but this is not always the case. For example it's common for a clock to bind to a reset device or also expose a syscon if the clock register map is also used to apply special configuration.

In such case, on accessing a device as a clock, the bootloader crash. To correctly handle this, check if the child device is actually a clock and ignore otherwise.

Fixes 6b7fd3128f71 ("clk: fix set_rate to clean up cached rates for the hierarchy")

---
RESEND as there was a problem with email To:

 drivers/clk/clk-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/clk-uclass.c +3 -0
index 353ae476068..8f3309d9530 100644
@@ -554,6 +554,9 @@ static void clk_clean_rate_cache(struct clk *clk)
 	clk->rate = 0;
 
 	list_for_each_entry(child_dev, &clk->dev->child_head, sibling_node) {
+		if (device_get_uclass_id(child_dev) != UCLASS_CLK)
+			continue;
+
 		clkp = dev_get_clk_ptr(child_dev);
 		clk_clean_rate_cache(clkp);
 	}
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 35 lines · Christian Marangi

It's currently possible to make the bootloader crash on calling clk_set_rate caused by the loop in clk_clean_rate_cache.

The loop assume that every child of the clock node are also clock device but this is not always the case. For example it's common for a clock to bind to a reset device or also expose a syscon if the clock register map is also used to apply special configuration.

In such case, on accessing a device as a clock, the bootloader crash. To correctly handle this, check if the child device is actually a clock and ignore otherwise.

Fixes 6b7fd3128f71 ("clk: fix set_rate to clean up cached rates for the

hierarchy")

---
RESEND as there was a problem with email To:

 drivers/clk/clk-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/clk-uclass.c +3 -0
index 353ae476068..8f3309d9530 100644
@@ -554,6 +554,9 @@ static void clk_clean_rate_cache(struct clk *clk)
        clk->rate = 0;
 
        list_for_each_entry(child_dev, &clk->dev->child_head,
 sibling_node) {
+               if (device_get_uclass_id(child_dev) != UCLASS_CLK)
+                       continue;
+
                clkp = dev_get_clk_ptr(child_dev);
                clk_clean_rate_cache(clkp);
Quoted 2 lines
        }

Michael

Quoted 4 lines

--
2.48.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#2 lore raw
In reply to Christian Marangi
Quoted 37 lines · Christian Marangi

It's currently possible to make the bootloader crash on calling clk_set_rate caused by the loop in clk_clean_rate_cache.

The loop assume that every child of the clock node are also clock device but this is not always the case. For example it's common for a clock to bind to a reset device or also expose a syscon if the clock register map is also used to apply special configuration.

In such case, on accessing a device as a clock, the bootloader crash. To correctly handle this, check if the child device is actually a clock and ignore otherwise.

Fixes 6b7fd3128f71 ("clk: fix set_rate to clean up cached rates for the hierarchy")

---
RESEND as there was a problem with email To:

 drivers/clk/clk-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/clk-uclass.c +3 -0
index 353ae476068..8f3309d9530 100644
@@ -554,6 +554,9 @@ static void clk_clean_rate_cache(struct clk *clk)
 	clk->rate = 0;
 
 	list_for_each_entry(child_dev, &clk->dev->child_head, sibling_node) {
+		if (device_get_uclass_id(child_dev) != UCLASS_CLK)
+			continue;
+
 		clkp = dev_get_clk_ptr(child_dev);
 		clk_clean_rate_cache(clkp);
 	}
Signature · 1 line
2.48.1

News for this trivial patch?

Signature · 1 line
	Ansuel
#3 lore raw

Hi Fabio

Quoted 41 lines · Christian Marangi
Quoted 8 lines · Christian Marangi

It's currently possible to make the bootloader crash on calling clk_set_rate caused by the loop in clk_clean_rate_cache.

The loop assume that every child of the clock node are also clock device but this is not always the case. For example it's common for a clock to bind to a reset device or also expose a syscon if the clock register map is also used to apply special configuration.

Quoted 5 lines

In such case, on accessing a device as a clock, the bootloader crash. To correctly handle this, check if the child device is actually a clock and ignore otherwise.

Fixes 6b7fd3128f71 ("clk: fix set_rate to clean up cached rates for the

hierarchy")

Quoted 12 lines

---
RESEND as there was a problem with email To:

 drivers/clk/clk-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/clk-uclass.c +0 -0
index 353ae476068..8f3309d9530 100644

drivers/clk/clk-uclass.c static void clk_clean_rate_cache(struct clk *clk) · line 556

Quoted 3 lines
drivers/clk/clk-uclass.c +0 -0
@@ -554,6 +554,9 @@ static void clk_clean_rate_cache(struct clk *clk)
      clk->rate = 0;
 
      list_for_each_entry(child_dev, &clk->dev->child_head,

sibling_node) {

Quoted 9 lines
drivers/clk/clk-uclass.c +3 -1
+             if (device_get_uclass_id(child_dev) != UCLASS_CLK)
+                     continue;
+
              clkp = dev_get_clk_ptr(child_dev);
              clk_clean_rate_cache(clkp);
      }
--

2.48.1

Quoted 3 lines

News for this trivial patch?

Can you review it and pick if needed?

Michael

Quoted 3 lines

--
Ansuel

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#4 lore raw
Quoted 1 line · Michael Nazzareno Trimarchi

Can you review it and pick if needed?

This is not assigned to me in patchwork as it is not i.MX related.

Someone else needs to handle it.

#5 lore raw

Hi

Il lun 7 apr 2025, 22:03 Fabio Estevam <[email protected]> ha scritto:

Quoted 9 lines
Quoted 1 line · Michael Nazzareno Trimarchi

Can you review it and pick if needed?

This is not assigned to me in patchwork as it is not i.MX related.

Someone else needs to handle it.

I was thinking that you are handle clk tree too. My mistake

Michael

Quoted 1 line
#6 lore raw

Il giorno mar 8 apr 2025 alle ore 07:56 Michael Nazzareno Trimarchi <[email protected]> ha scritto:

Quoted 14 lines

Hi

Il lun 7 apr 2025, 22:03 Fabio Estevam <[email protected]> ha scritto:

Quoted 9 lines
Quoted 1 line · Michael Nazzareno Trimarchi

Can you review it and pick if needed?

This is not assigned to me in patchwork as it is not i.MX related.

Someone else needs to handle it.

Any news for this? Maybe Tom can ping some maintainers for this fix?

#7 lore raw
In reply to Christian Marangi
Quoted 9 lines · Christian Marangi

It's currently possible to make the bootloader crash on calling clk_set_rate caused by the loop in clk_clean_rate_cache.

The loop assume that every child of the clock node are also clock device but this is not always the case. For example it's common for a clock to bind to a reset device or also expose a syscon if the clock register map is also used to apply special configuration.

[...]

Applied to u-boot/master, thanks!

[1/1] clk: fix crash on clk_set_rate clean rate cache

      commit: aa96cda0a58f4d181b81a897b0b9fea3d9729478
Signature · 1 line
Tom