From: Wenhua Lin <Wenhua.Lin@unisoc.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Orson Zhai <orsonzhai@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Cixi Geng <cixi.geng@linux.dev>, <linux-kernel@vger.kernel.org>,
<linux-serial@vger.kernel.org>,
wenhua lin <wenhua.lin1994@gmail.com>,
Wenhua Lin <Wenhua.Lin@unisoc.com>,
Xiongpeng Wu <xiongpeng.wu@unisoc.com>,
Zhaochen Su <Zhaochen.Su@unisoc.com>,
Zhirong Qiu <Zhirong.Qiu@unisoc.com>
Subject: [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock
Date: Wed, 10 Dec 2025 14:35:43 +0800 [thread overview]
Message-ID: <20251210063543.2185727-1-Wenhua.Lin@unisoc.com> (raw)
Simplify the code which fetches the input clock by using
devm_clk_get_optional(). If no input clock is present
devm_clk_get_optional() will return NULL instead of an error
which matches the behavior of the old code.
Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
---
Change in V2:
-Change title.
-Change commit message.
-Replace devm_clk_get() by devm_clk_get_optional() and drop NULL assignment.
-Delete the sprd_uart_is_console function, after using the devm_clk_get_optional()
interface, this conditional check is redundant.
---
drivers/tty/serial/sprd_serial.c | 40 +++++++-------------------------
1 file changed, 9 insertions(+), 31 deletions(-)
diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index 8c9366321f8e..83ce77b435ee 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -1115,34 +1115,21 @@ static void sprd_remove(struct platform_device *dev)
uart_unregister_driver(&sprd_uart_driver);
}
-static bool sprd_uart_is_console(struct uart_port *uport)
-{
- struct console *cons = sprd_uart_driver.cons;
-
- if ((cons && cons->index >= 0 && cons->index == uport->line) ||
- of_console_check(uport->dev->of_node, SPRD_TTY_NAME, uport->line))
- return true;
-
- return false;
-}
-
static int sprd_clk_init(struct uart_port *uport)
{
struct clk *clk_uart, *clk_parent;
struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
- clk_uart = devm_clk_get(uport->dev, "uart");
+ clk_uart = devm_clk_get_optional(uport->dev, "uart");
if (IS_ERR(clk_uart)) {
- dev_warn(uport->dev, "uart%d can't get uart clock\n",
- uport->line);
- clk_uart = NULL;
+ return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
+ "uart%d can't get uart clock\n", uport->line);
}
- clk_parent = devm_clk_get(uport->dev, "source");
+ clk_parent = devm_clk_get_optional(uport->dev, "source");
if (IS_ERR(clk_parent)) {
- dev_warn(uport->dev, "uart%d can't get source clock\n",
- uport->line);
- clk_parent = NULL;
+ return dev_err_probe(uport->dev, PTR_ERR(clk_parent),
+ "uart%d can't get source clock\n", uport->line);
}
if (!clk_uart || clk_set_parent(clk_uart, clk_parent))
@@ -1150,19 +1137,10 @@ static int sprd_clk_init(struct uart_port *uport)
else
uport->uartclk = clk_get_rate(clk_uart);
- u->clk = devm_clk_get(uport->dev, "enable");
+ u->clk = devm_clk_get_optional(uport->dev, "enable");
if (IS_ERR(u->clk)) {
- if (PTR_ERR(u->clk) == -EPROBE_DEFER)
- return -EPROBE_DEFER;
-
- dev_warn(uport->dev, "uart%d can't get enable clock\n",
- uport->line);
-
- /* To keep console alive even if the error occurred */
- if (!sprd_uart_is_console(uport))
- return PTR_ERR(u->clk);
-
- u->clk = NULL;
+ return dev_err_probe(uport->dev, PTR_ERR(u->clk),
+ "uart%d can't get enable clock\n", uport->line);
}
return 0;
--
2.34.1
next reply other threads:[~2025-12-10 6:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 6:35 Wenhua Lin [this message]
2025-12-10 7:12 ` Chunyan Zhang
2025-12-10 7:36 ` wenhua lin
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=20251210063543.2185727-1-Wenhua.Lin@unisoc.com \
--to=wenhua.lin@unisoc.com \
--cc=Zhaochen.Su@unisoc.com \
--cc=Zhirong.Qiu@unisoc.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=cixi.geng@linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=wenhua.lin1994@gmail.com \
--cc=xiongpeng.wu@unisoc.com \
--cc=zhang.lyra@gmail.com \
/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®