* [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure
@ 2026-12-01 19:17 Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 1/2] serial: owl: Disable the clock when uart_add_one_port() fails Arina Kharlamova via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:17 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Andreas Färber,
Manivannan Sadhasivam, Amit Singh Tomar, Peter Korsgaard,
Shubhrajyoti Datta
Cc: linux-kernel, linux-serial, linux-arm-kernel, linux-actions,
kernel test robot, Dan Carpenter, Arina Kharlamova
Two serial drivers leave the port clock enabled when probe fails
after enabling it. uartlite also leaves runtime PM enabled.
I found these with spec2patch. I model-checked the probe and remove
paths of each driver with CBMC against formal specifications of the
kernel APIs they call. The specifications are checked against the kernel
source, and some of them are proved in Rocq against a transcription of
the kernel code. I also checked lock usage separately. With the help of
an AI coding assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.
---
Arina Kharlamova (2):
serial: owl: Disable the clock when uart_add_one_port() fails
serial: uartlite: Undo clock and runtime PM setup on probe failure
drivers/tty/serial/owl-uart.c | 4 +++-
drivers/tty/serial/uartlite.c | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261201-s2p-tty1-ee20b0ff657a
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] serial: owl: Disable the clock when uart_add_one_port() fails
2026-12-01 19:17 [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure Arina Kharlamova via B4 Relay
@ 2026-12-01 19:17 ` Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure Arina Kharlamova via B4 Relay
2026-12-01 19:23 ` [PATCH 0/2] serial: owl, uartlite: undo clock " sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:17 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Andreas Färber,
Manivannan Sadhasivam, Amit Singh Tomar, Peter Korsgaard,
Shubhrajyoti Datta
Cc: linux-kernel, linux-serial, linux-arm-kernel, linux-actions,
kernel test robot, Dan Carpenter, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
owl_uart_probe() enables the port clock with clk_prepare_enable()
before it registers the port. If uart_add_one_port() fails, probe
clears the owl_uart_ports[] slot and returns the error, but the clock
is left prepared and enabled. owl_uart_remove() is not called after a
failed probe, so nothing disables it.
Call clk_disable_unprepare() on this path too, as is already done when
the clock rate is zero.
Fixes: abf42d2f333b ("tty: serial: owl: add "much needed" clk_prepare_enable()")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202609160937.OilPQS0m-lkp@intel.com/
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/tty/serial/owl-uart.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c
index 863363ddad00..98e6c1fec66f 100644
--- a/drivers/tty/serial/owl-uart.c
+++ b/drivers/tty/serial/owl-uart.c
@@ -713,8 +713,10 @@ static int owl_uart_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, owl_port);
ret = uart_add_one_port(&owl_uart_driver, &owl_port->port);
- if (ret)
+ if (ret) {
owl_uart_ports[pdev->id] = NULL;
+ clk_disable_unprepare(owl_port->clk);
+ }
return ret;
}
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure
2026-12-01 19:17 [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 1/2] serial: owl: Disable the clock when uart_add_one_port() fails Arina Kharlamova via B4 Relay
@ 2026-12-01 19:17 ` Arina Kharlamova via B4 Relay
2026-12-01 19:23 ` sashiko-bot
2026-12-01 19:23 ` [PATCH 0/2] serial: owl, uartlite: undo clock " sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:17 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Andreas Färber,
Manivannan Sadhasivam, Amit Singh Tomar, Peter Korsgaard,
Shubhrajyoti Datta
Cc: linux-kernel, linux-serial, linux-arm-kernel, linux-actions,
Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
ulite_probe() enables the clock with clk_prepare_enable() and enables
runtime PM before it calls ulite_assign(). If ulite_assign() fails,
for example because the port number is not below ULITE_NR_UARTS, probe
only drops its usage count and returns the error. The clock is left
prepared and enabled and runtime PM is left enabled. A later probe of
the same device then calls pm_runtime_enable() again and gets the
"Unbalanced pm_runtime_enable!" warning.
When ulite_assign() fails, disable runtime PM, drop the usage count
without idling the device and disable and unprepare the clock.
Fixes: 14288befeb57 ("tty: serial: uartlite: Add clock adaptation")
Fixes: 5bbe10a6942d ("tty: serial: uartlite: Add runtime pm support")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/tty/serial/uartlite.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index b9a14dc2f2fd..d2dfdfde72a2 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -881,6 +881,13 @@ of_err:
pm_runtime_enable(&pdev->dev);
ret = ulite_assign(&pdev->dev, id, res->start, irq, pdata);
+ if (ret) {
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_set_suspended(&pdev->dev);
+ pm_runtime_put_noidle(&pdev->dev);
+ clk_disable_unprepare(pdata->clk);
+ return ret;
+ }
pm_runtime_mark_last_busy(&pdev->dev);
pm_runtime_put_autosuspend(&pdev->dev);
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure
2026-12-01 19:17 ` [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure Arina Kharlamova via B4 Relay
@ 2026-12-01 19:23 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-01 19:23 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-serial
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] serial: uartlite: clock underflow and wrong teardown order in
ulite_remove() [1]
--
commit 836e2a7f4a7eacabfa56b7b7ef2b7ad0fda56104
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
serial: uartlite: Undo clock and runtime PM setup on probe failure
This commit disables runtime PM, drops the runtime PM usage count, and
disables and unprepares the clock when ulite_assign() fails in
ulite_probe().
> diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
> index b9a14dc2f2fdf..d2dfdfde72a25 100644
> --- a/drivers/tty/serial/uartlite.c
> +++ b/drivers/tty/serial/uartlite.c
> @@ -881,6 +881,13 @@ static int ulite_probe(struct platform_device *pdev)
> pm_runtime_enable(&pdev->dev);
>
> ret = ulite_assign(&pdev->dev, id, res->start, irq, pdata);
> + if (ret) {
> + pm_runtime_disable(&pdev->dev);
> + pm_runtime_set_suspended(&pdev->dev);
> + pm_runtime_put_noidle(&pdev->dev);
> + clk_disable_unprepare(pdata->clk);
> + return ret;
> + }
>
> pm_runtime_mark_last_busy(&pdev->dev);
> pm_runtime_put_autosuspend(&pdev->dev);
[Severity: High]
This problem wasn't introduced by this patch, but can ulite_remove()
[1] underflow pdata->clk and access ULITE_CONTROL with the clock
gated?
drivers/tty/serial/uartlite.c:ulite_remove() {
struct uart_port *port = dev_get_drvdata(&pdev->dev);
struct uartlite_data *pdata = port->private_data;
clk_disable_unprepare(pdata->clk);
ulite_release(&pdev->dev);
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
pm_runtime_dont_use_autosuspend(&pdev->dev);
}
When the port is runtime-suspended at driver unbind, the
pm_runtime_get_sync() / pm_runtime_put_sync() cycle in
__device_release_driver() immediately re-suspends the device via
ulite_runtime_suspend(), which calls clk_disable(pdata->clk). Calling
clk_disable_unprepare(pdata->clk) unconditionally at the start of
ulite_remove() then disables an already disabled clock.
Disabling and unpreparing pdata->clk before ulite_release() calls
uart_remove_one_port() also leaves the AXI clock gated when
ulite_shutdown() accesses ULITE_CONTROL, and causes child serial-base
unregistration to call clk_enable() on an unprepared clock in
ulite_runtime_resume(). In addition, ulite_release() clears drvdata with
dev_set_drvdata(dev, NULL) before pm_runtime_disable() runs, so a
concurrent runtime PM callback can dereference a NULL port pointer from
dev_get_drvdata().
[1] https://sashiko.dev/#/bug/linux-f6fc2c71-7926-4155-b602-d912aee2abb8
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-s2p-tty1-v1-0-731a5142143c@mbzuai.ac.ae?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure
2026-12-01 19:17 [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 1/2] serial: owl: Disable the clock when uart_add_one_port() fails Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure Arina Kharlamova via B4 Relay
@ 2026-12-01 19:23 ` sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-01 19:23 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-serial
Sashiko has finished reviewing this 2-patch series:
- Patch 1: no issues found.
- Patch 2 ("serial: uartlite: Undo clock and runtime PM setup on..."): 1
related pre-existing bug noted
A detailed review has been sent as a separate reply to patch 2.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-s2p-tty1-v1-0-731a5142143c@mbzuai.ac.ae
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 19:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:17 [PATCH 0/2] serial: owl, uartlite: undo clock setup on probe failure Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 1/2] serial: owl: Disable the clock when uart_add_one_port() fails Arina Kharlamova via B4 Relay
2026-12-01 19:17 ` [PATCH 2/2] serial: uartlite: Undo clock and runtime PM setup on probe failure Arina Kharlamova via B4 Relay
2026-12-01 19:23 ` sashiko-bot
2026-12-01 19:23 ` [PATCH 0/2] serial: owl, uartlite: undo clock " sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox