Skip to contentSkip to conversation

clk: bcm: rpi: Don't register as OF provider if !dev->np

PATCH In review Nicolas Saenz Julienne 4 participants 4 messages Mar 25, 2021 – Mar 26, 2021

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

PATCH 1/1 clk: bcm: rpi: Don't register as OF provider if !dev->np

There are two ways clk-raspberrypi might be registered: through device-tree or through an explicit platform device registration. The latter happens after firmware/raspberrypi's probe, and it's limited to RPi3s, which solely use the ARM clock to scale CPU's frequency. That clock is matched with cpu0's device thanks to the ARM clock being registered as a clkdev.

In that scenario, don't register the device as an OF clock provider, as it makes no sense and will cause trouble.

Fixes d4b4f1b6b97e ("clk: bcm: rpi: Add DT provider for the clocks")
---
 drivers/clk/bcm/clk-raspberrypi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/clk/bcm/clk-raspberrypi.c +6 -4
index f89b9cfc4309..27e85687326f 100644
@@ -337,10 +337,12 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
-					  clk_data);
-	if (ret)
-		return ret;
+	if (dev->of_node) {
+		ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+						  clk_data);
+		if (ret)
+			return ret;
+	}
 
 	rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq",
 						     -1, NULL, 0);
Signature · 1 line
2.30.2
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Nicolas Saenz Julienne

There are two ways clk-raspberrypi might be registered: through device-tree or through an explicit platform device registration. The latter happens after firmware/raspberrypi's probe, and it's limited to RPi3s, which solely use the ARM clock to scale CPU's frequency. That clock is matched with cpu0's device thanks to the ARM clock being registered as a clkdev.

Quoted 6 lines

In that scenario, don't register the device as an OF clock provider, as it makes no sense and will cause trouble.

Fixes d4b4f1b6b97e ("clk: bcm: rpi: Add DT provider for the clocks")
Quoted 15 lines
---
  drivers/clk/bcm/clk-raspberrypi.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/clk/bcm/clk-raspberrypi.c +0 -3
index f89b9cfc4309..27e85687326f 100644
@@ -337,10 +337,12 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)
  	if (ret)
  		return ret;
 
-	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
-					  clk_data);
-	if (ret)

drivers/clk/bcm/clk-raspberrypi.c static int raspberrypi_clk_probe(struct platform_device *pdev) · line 348

Quoted 10 lines
drivers/clk/bcm/clk-raspberrypi.c +6 -1
-		return ret;
+	if (dev->of_node) {
+		ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+						  clk_data);
+		if (ret)
+			return ret;
+	}
 
  	rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq",
  						     -1, NULL, 0);

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
maintainer
#2 lore raw
In reply to Nicolas Saenz Julienne

Quoting Nicolas Saenz Julienne (2021-03-25 11:57:48)

Quoted 9 lines

There are two ways clk-raspberrypi might be registered: through device-tree or through an explicit platform device registration. The latter happens after firmware/raspberrypi's probe, and it's limited to RPi3s, which solely use the ARM clock to scale CPU's frequency. That clock is matched with cpu0's device thanks to the ARM clock being registered as a clkdev.

In that scenario, don't register the device as an OF clock provider, as it makes no sense and will cause trouble.

What sort of trouble?

Quoted 13 lines
Fixes d4b4f1b6b97e ("clk: bcm: rpi: Add DT provider for the clocks")
---
 drivers/clk/bcm/clk-raspberrypi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/clk/bcm/clk-raspberrypi.c +0 -0
index f89b9cfc4309..27e85687326f 100644

drivers/clk/bcm/clk-raspberrypi.c static int raspberrypi_clk_probe(struct platform_device *pdev) · line 340

Quoted 8 lines
drivers/clk/bcm/clk-raspberrypi.c +1 -4
@@ -337,10 +337,12 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
-       ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
-                                         clk_data);
-       if (ret)
-               return ret;
+       if (dev->of_node) {

Can you add a comment to the code indicating the problem this is fixing? I fear that we'll look back on this later and simply remove this if condition because it's "redundant". Better to have some code comment so we don't have to look up git history to figure out that we only call this when the of node is populated. I'm not sure I understand what goes wrong though. Won't the absence of dev->of_node mean the provider doesn't do anything?

Quoted 8 lines
drivers/clk/bcm/clk-raspberrypi.c +5 -0
+               ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+                                                 clk_data);
+               if (ret)
+                       return ret;
+       }
 
        rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq",
                                                     -1, NULL, 0);
#3 lore raw
Quoted 8 lines · Stephen Boyd

Quoting Nicolas Saenz Julienne (2021-03-25 11:57:48)

Quoted 7 lines

There are two ways clk-raspberrypi might be registered: through device-tree or through an explicit platform device registration. The latter happens after firmware/raspberrypi's probe, and it's limited to RPi3s, which solely use the ARM clock to scale CPU's frequency. That clock is matched with cpu0's device thanks to the ARM clock being registered as a clkdev.

Quoted 4 lines
Quoted 2 lines

In that scenario, don't register the device as an OF clock provider, as it makes no sense and will cause trouble.

What sort of trouble?

A crash
https://lore.kernel.org/linux-acpi/[email protected]/

Quoted 15 lines
Quoted 15 lines
Fixes d4b4f1b6b97e ("clk: bcm: rpi: Add DT provider for the clocks")
---
 drivers/clk/bcm/clk-raspberrypi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/clk/bcm/clk-raspberrypi.c +0 -0
index f89b9cfc4309..27e85687326f 100644
@@ -337,10 +337,12 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
Quoted 13 lines

drivers/clk/bcm/clk-raspberrypi.c static int raspberrypi_clk_probe(struct platform_device *pdev) · line 340

Quoted 5 lines
drivers/clk/bcm/clk-raspberrypi.c +1 -4
-       ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
-                                         clk_data);
-       if (ret)
-               return ret;
+       if (dev->of_node) {

Can you add a comment to the code indicating the problem this is fixing? I fear that we'll look back on this later and simply remove this if condition because it's "redundant". Better to have some code comment so we don't have to look up git history to figure out that we only call this when the of node is populated. I'm not sure I understand what goes wrong though. Won't the absence of dev->of_node mean the provider doesn't do anything?

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