All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: max310x: simplify clock management with devm_clk_get_optional_enabled()
@ 2026-12-02 16:28 Hugo Villeneuve
  2026-12-02 16:40 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Hugo Villeneuve @ 2026-12-02 16:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Hugo Villeneuve, linux-kernel, linux-serial

Use devm_clk_get_optional_enabled() helper instead of calling
devm_clk_get_optional() and then clk_prepare_enable(). This simplifies
cleanup code on probe failure or driver detach and allows to remove
out_clk label and associated gotos.

Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
---
 drivers/tty/serial/max310x.c | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index de8a1f05cf30e..8a71127c29210 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1880,23 +1880,17 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 
 	xtal = device_property_match_string(dev, "clock-names", "osc") < 0;
 	if (xtal)
-		s->clk = devm_clk_get_optional(dev, "xtal");
+		s->clk = devm_clk_get_optional_enabled(dev, "xtal");
 	else
-		s->clk = devm_clk_get_optional(dev, "osc");
+		s->clk = devm_clk_get_optional_enabled(dev, "osc");
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
 
-	ret = clk_prepare_enable(s->clk);
-	if (ret)
-		return ret;
-
 	freq = clk_get_rate(s->clk);
 	if (freq == 0)
 		freq = uartclk;
-	if (freq == 0) {
-		ret = dev_err_probe(dev, -EINVAL, "Cannot get clock rate\n");
-		goto out_clk;
-	}
+	if (freq == 0)
+		return dev_err_probe(dev, -EINVAL, "Cannot get clock rate\n");
 
 	if (xtal) {
 		fmin = 1000000;
@@ -1907,10 +1901,8 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 	}
 
 	/* Check frequency limits */
-	if (freq < fmin || freq > fmax) {
-		ret = -ERANGE;
-		goto out_clk;
-	}
+	if (freq < fmin || freq > fmax)
+		return -ERANGE;
 
 	s->regmap = regmaps[0];
 	s->devtype = devtype;
@@ -1920,7 +1912,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 	/* Check device to ensure we are talking to what we expect */
 	ret = max310x_detect(dev);
 	if (ret)
-		goto out_clk;
+		return ret;
 
 	for (i = 0; i < devtype->nr; i++) {
 		unsigned int val;
@@ -2082,9 +2074,6 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 			uart_remove_one_port(&max310x_uart, &s->p[i].port);
 	}
 
-out_clk:
-	clk_disable_unprepare(s->clk);
-
 	return ret;
 }
 
@@ -2105,8 +2094,6 @@ static void max310x_remove(struct device *dev)
 
 		max310x_power(&s->p[i].port, 0);
 	}
-
-	clk_disable_unprepare(s->clk);
 }
 
 static const struct of_device_id __maybe_unused max310x_dt_ids[] = {

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 16:28 [PATCH] serial: max310x: simplify clock management with devm_clk_get_optional_enabled() Hugo Villeneuve
2026-12-02 16:40 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.