From: Hugo Villeneuve <hugo@hugovil.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Hugo Villeneuve <hugo@hugovil.com>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH] serial: max310x: simplify clock management with devm_clk_get_optional_enabled()
Date: Wed, 2 Dec 2026 11:28:18 -0500 [thread overview]
Message-ID: <20261202162824.34779-1-hugo@hugovil.com> (raw)
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
reply other threads:[~2026-12-02 16:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202162824.34779-1-hugo@hugovil.com \
--to=hugo@hugovil.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®