Skip to contentSkip to conversation

serial: 8250_bcm7271: Fix clock handling

PATCH In review Doug Berger 3 participants 7 messages Apr 27, 2023 – Apr 28, 2023

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

cover serial: 8250_bcm7271: Fix clock handling

XuDong Liu offered a patch to correct some clock issues detected in the probe function and Christophe JAILLET pointed out that there was a similar issue in remove.

Since no V2 has appeared, I am providing this pair of commits to address both cases. This set chooses to use a managed clock to avoid the need to explicitly call clk_put from the driver.

Doug Berger (2):
serial: 8250_bcm7271: balance clk_enable calls
serial: 8250_bcm7271: fix leak in brcmuart_probe

 drivers/tty/serial/8250/8250_bcm7271.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 serial: 8250_bcm7271: balance clk_enable calls

The sw_baud clock must be disabled when the device driver is not connected to the device. This now occurs when probe fails and upon remove.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
---
 drivers/tty/serial/8250/8250_bcm7271.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +4 -1
index f801b1f5b46c..90ee7bc12f77 100644
@@ -1032,7 +1032,7 @@ static int brcmuart_probe(struct platform_device *pdev)
 	if (clk_rate == 0) {
 		dev_err(dev, "clock-frequency or clk not defined\n");
 		ret = -EINVAL;
-		goto release_dma;
+		goto err_clk_disable;
 	}
 
 	dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not ");
@@ -1119,6 +1119,8 @@ static int brcmuart_probe(struct platform_device *pdev)
 	serial8250_unregister_port(priv->line);
 err:
 	brcmuart_free_bufs(dev, priv);
+err_clk_disable:
+	clk_disable_unprepare(baud_mux_clk);
 release_dma:
 	if (priv->dma_enabled)
 		brcmuart_arbitration(priv, 0);
@@ -1133,6 +1135,7 @@ static int brcmuart_remove(struct platform_device *pdev)
 	hrtimer_cancel(&priv->hrt);
 	serial8250_unregister_port(priv->line);
 	brcmuart_free_bufs(&pdev->dev, priv);
+	clk_disable_unprepare(priv->baud_mux_clk);
 	if (priv->dma_enabled)
 		brcmuart_arbitration(priv, 0);
 	return 0;
Signature · 1 line
2.34.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls

Quoted 8 lines · Doug Berger

The sw_baud clock must be disabled when the device driver is not connected to the device. This now occurs when probe fails and upon remove.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Signature · 1 line
Florian
#3 lore raw

PATCH 2/2 serial: 8250_bcm7271: fix leak in `brcmuart_probe`

In reply to Doug Berger

Smatch reports:
drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.

The issue is fixed by using a managed clock.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
---
 drivers/tty/serial/8250/8250_bcm7271.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +1 -1
index 90ee7bc12f77..af0e1c070187 100644
@@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device *pdev)
 	of_property_read_u32(np, "clock-frequency", &clk_rate);
 
 	/* See if a Baud clock has been specified */
-	baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
+	baud_mux_clk = devm_clk_get(dev, "sw_baud");
 	if (IS_ERR(baud_mux_clk)) {
 		if (PTR_ERR(baud_mux_clk) == -EPROBE_DEFER) {
 			ret = -EPROBE_DEFER;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`

Le 27/04/2023 à 20:19, Doug Berger a écrit :

Quoted 19 lines

Smatch reports:
drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.

The issue is fixed by using a managed clock.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
---
  drivers/tty/serial/8250/8250_bcm7271.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +0 -0
index 90ee7bc12f77..af0e1c070187 100644

drivers/tty/serial/8250/8250_bcm7271.c static int brcmuart_probe(struct platform_device *pdev) · line 1015

Quoted 5 lines
drivers/tty/serial/8250/8250_bcm7271.c +1 -1
@@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device *pdev)
  	of_property_read_u32(np, "clock-frequency", &clk_rate);
 
  	/* See if a Baud clock has been specified */
-	baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
+	baud_mux_clk = devm_clk_get(dev, "sw_baud");

If switching to devm_clk_get(), maybe devm_clk_get_enabled() could also be an option to fix both issues and avoid adding some LoC.

The order of operation in the remove function would then be different. I don't know if it can be an issue.

Just my 2c.

CJ

Quoted 3 lines
drivers/tty/serial/8250/8250_bcm7271.c +0 -0
  	if (IS_ERR(baud_mux_clk)) {
  		if (PTR_ERR(baud_mux_clk) == -EPROBE_DEFER) {
  			ret = -EPROBE_DEFER;
#5 lore raw

Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`

Quoted 28 lines · Christophe JAILLET

Le 27/04/2023 à 20:19, Doug Berger a écrit :

Quoted 19 lines

Smatch reports:
drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.

The issue is fixed by using a managed clock.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")

---
  drivers/tty/serial/8250/8250_bcm7271.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +0 -0
index 90ee7bc12f77..af0e1c070187 100644

drivers/tty/serial/8250/8250_bcm7271.c static int brcmuart_probe(struct platform_device · line 1015

Quoted 5 lines
drivers/tty/serial/8250/8250_bcm7271.c +1 -1
@@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device 
 *pdev)
       of_property_read_u32(np, "clock-frequency", &clk_rate);
       /* See if a Baud clock has been specified */
-    baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
+    baud_mux_clk = devm_clk_get(dev, "sw_baud");

If switching to devm_clk_get(), maybe devm_clk_get_enabled() could also be an option to fix both issues and avoid adding some LoC.

Quoted 1 line

The order of operation in the remove function would then be different. I don't know if it can be an issue.

I like the idea, but it doesn't backport to the source of the error. I'll try to remember to submit something after the merge closes.

Quoted 4 lines

Just my 2c.

CJ

Thanks!
Doug

Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`

In reply to Doug Berger
Quoted 10 lines · Doug Berger

Smatch reports:
drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.

The issue is fixed by using a managed clock.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Signature · 1 line
Florian