Skip to contentSkip to conversation

serial: 8250_bcm7271: Use devm_clk_get_optional_enabled()

PATCH In review Andy Shevchenko 2 participants 4 messages Oct 5, 2023

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

PATCH v2 1/1 serial: 8250_bcm7271: Use devm_clk_get_optional_enabled()

Use devm_clk_get_optional_enabled() to simplify the code.

---
v2: fixed the returned value (Andi)

 drivers/tty/serial/8250/8250_bcm7271.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/tty/serial/8250/8250_bcm7271.c +9 -15
index 1a853a08654a..55dea2539c47 100644
@@ -1015,26 +1015,23 @@ 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 = devm_clk_get(dev, "sw_baud");
-	if (IS_ERR(baud_mux_clk)) {
-		if (PTR_ERR(baud_mux_clk) == -EPROBE_DEFER) {
-			ret = -EPROBE_DEFER;
-			goto release_dma;
-		}
-		dev_dbg(dev, "BAUD MUX clock not specified\n");
-	} else {
+	baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud");
+	ret = PTR_ERR_OR_ZERO(baud_mux_clk);
+	if (ret)
+		goto release_dma;
+	if (baud_mux_clk) {
 		dev_dbg(dev, "BAUD MUX clock found\n");
-		ret = clk_prepare_enable(baud_mux_clk);
-		if (ret)
-			goto release_dma;
+
 		priv->baud_mux_clk = baud_mux_clk;
 		init_real_clk_rates(dev, priv);
 		clk_rate = priv->default_mux_rate;
+	} else {
+		dev_dbg(dev, "BAUD MUX clock not specified\n");
 	}
 
 	if (clk_rate == 0) {
 		ret = dev_err_probe(dev, -EINVAL, "clock-frequency or clk not defined\n");
-		goto err_clk_disable;
+		goto release_dma;
 	}
 
 	dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not ");
@@ -1118,8 +1115,6 @@ 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);
@@ -1134,7 +1129,6 @@ 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.40.0.1.gaa8946217a0b
Reviewed-by on v2 1/1
#1 lore raw

Hi Andy,

[...]

Quoted 13 lines
drivers/tty/serial/8250/8250_bcm7271.c +5 -8
-	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;
-			goto release_dma;
-		}
-		dev_dbg(dev, "BAUD MUX clock not specified\n");
-	} else {
+	baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud");
+	ret = PTR_ERR_OR_ZERO(baud_mux_clk);
+	if (ret)
+		goto release_dma;
+	if (baud_mux_clk) {

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

Quoted 10 lines
drivers/tty/serial/8250/8250_bcm7271.c +3 -3
 		dev_dbg(dev, "BAUD MUX clock found\n");
-		ret = clk_prepare_enable(baud_mux_clk);
-		if (ret)
-			goto release_dma;
+
 		priv->baud_mux_clk = baud_mux_clk;
 		init_real_clk_rates(dev, priv);
 		clk_rate = priv->default_mux_rate;
+	} else {
+		dev_dbg(dev, "BAUD MUX clock not specified\n");

little behavioral change here, but I don't think this is a problem.

Thanks,
Andi

#2 lore raw

On Thu, Oct 05, 2023 at 05:19:38PM +0200, Andi Shyti wrote:

[...]

Quoted 18 lines
Quoted 18 lines
drivers/tty/serial/8250/8250_bcm7271.c +6 -11
-	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;
-			goto release_dma;
-		}
-		dev_dbg(dev, "BAUD MUX clock not specified\n");
-	} else {
+	baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud");
+	ret = PTR_ERR_OR_ZERO(baud_mux_clk);
+	if (ret)
+		goto release_dma;
+	if (baud_mux_clk) {
 		dev_dbg(dev, "BAUD MUX clock found\n");
-		ret = clk_prepare_enable(baud_mux_clk);
-		if (ret)
-			goto release_dma;
+
Quoted 8 lines

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

Quoted 5 lines
drivers/tty/serial/8250/8250_bcm7271.c +2 -0
 		priv->baud_mux_clk = baud_mux_clk;
 		init_real_clk_rates(dev, priv);
 		clk_rate = priv->default_mux_rate;
+	} else {
+		dev_dbg(dev, "BAUD MUX clock not specified\n");

little behavioral change here, but I don't think this is a problem.

You meant that "if (!x) else" had been changed to "if (x) else" semantics? Otherwise I don't see any difference.

Quoted 1 line

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Hi Andy,

Quoted 31 lines · Andy Shevchenko

On Thu, Oct 05, 2023 at 05:19:38PM +0200, Andi Shyti wrote:

[...]

Quoted 18 lines
Quoted 18 lines
drivers/tty/serial/8250/8250_bcm7271.c +6 -11
-	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;
-			goto release_dma;
-		}
-		dev_dbg(dev, "BAUD MUX clock not specified\n");
-	} else {
+	baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud");
+	ret = PTR_ERR_OR_ZERO(baud_mux_clk);
+	if (ret)
+		goto release_dma;
+	if (baud_mux_clk) {
 		dev_dbg(dev, "BAUD MUX clock found\n");
-		ret = clk_prepare_enable(baud_mux_clk);
-		if (ret)
-			goto release_dma;
+
Quoted 8 lines

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

Quoted 5 lines
drivers/tty/serial/8250/8250_bcm7271.c +2 -0
 		priv->baud_mux_clk = baud_mux_clk;
 		init_real_clk_rates(dev, priv);
 		clk_rate = priv->default_mux_rate;
+	} else {
+		dev_dbg(dev, "BAUD MUX clock not specified\n");

little behavioral change here, but I don't think this is a problem.

Quoted 2 lines

You meant that "if (!x) else" had been changed to "if (x) else" semantics? Otherwise I don't see any difference.

If devm_clk_get() fails with anything but -EPROBE_DEFER originally the code was not returning, while now it returns.

But still... this is perfectly fine.

Andi

Quoted 8 lines
Quoted 1 line

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko