* [PATCH v2] serial: uartlite: Disable the clock after the port is removed
@ 2026-12-03 11:09 Arina Kharlamova via B4 Relay
2026-12-03 11:23 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-03 11:09 UTC (permalink / raw)
To: Peter Korsgaard, Greg Kroah-Hartman, Jiri Slaby,
Shubhrajyoti Datta
Cc: linux-serial, linux-kernel, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
ulite_remove() calls clk_disable_unprepare() before ulite_release().
When the port is open, ulite_startup() holds a second clk_enable(), so
the clock is unprepared while still enabled, and then
uart_remove_one_port() runs ulite_shutdown(), which writes
ULITE_CONTROL and calls clk_disable() on the unprepared clock. For a
console port the clock is gated before the console is unregistered.
The device can also runtime suspend during the remove. The
pm_runtime_put_sync() that the driver core calls before ->remove()
arms the autosuspend timer, or suspends at once when
autosuspend_delay_ms is 0. ulite_runtime_suspend() then disables the
clock a second time, and after ulite_release() it dereferences the
cleared drvdata.
Hold a runtime PM reference across ulite_release(), so the device is
resumed and cannot suspend while the port is torn down. Disable the
clock after runtime PM is disabled, and only if the device is not
runtime suspended, then unprepare it.
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>
---
I noticed this while reviewing a related fix in the same driver. With
the help of an AI coding assistant (Claude); I reviewed the analysis and
the fix. Compile-tested only, not tested on hardware.
---
Changes in v2:
- Disable and unprepare the clock after ulite_release(), so
ulite_shutdown() and the console unregister run with the clock on
(Sashiko review).
- Skip clk_disable() if the device stayed suspended because
pm_runtime_get_sync() failed.
- Fixes: add 14288befeb57, which added the clock calls in this order,
instead of 6a7ce07d6cb7.
- New subject.
- Link to v1: https://patch.msgid.link/20261201-uartlite-remove-clk-v1-1-bdffc49566f6@mbzuai.ac.ae
---
drivers/tty/serial/uartlite.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index b9a14dc2f2fd..b6d5cd462886 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -893,9 +893,13 @@ static void ulite_remove(struct platform_device *pdev)
struct uart_port *port = dev_get_drvdata(&pdev->dev);
struct uartlite_data *pdata = port->private_data;
- clk_disable_unprepare(pdata->clk);
+ pm_runtime_get_sync(&pdev->dev);
ulite_release(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ clk_disable(pdata->clk);
+ clk_unprepare(pdata->clk);
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
pm_runtime_dont_use_autosuspend(&pdev->dev);
}
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261201-uartlite-remove-clk-9dfc2176f6c9
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] serial: uartlite: Disable the clock after the port is removed
2026-12-03 11:09 [PATCH v2] serial: uartlite: Disable the clock after the port is removed Arina Kharlamova via B4 Relay
@ 2026-12-03 11:23 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 11:23 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-serial
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> ulite_remove() calls clk_disable_unprepare() before ulite_release().
> When the port is open, ulite_startup() holds a second clk_enable(), so
> the clock is unprepared while still enabled, and then
> uart_remove_one_port() runs ulite_shutdown(), which writes
> ULITE_CONTROL and calls clk_disable() on the unprepared clock. For a
> console port the clock is gated before the console is unregistered.
>
> The device can also runtime suspend during the remove. The
> pm_runtime_put_sync() that the driver core calls before ->remove()
> arms the autosuspend timer, or suspends at once when
> autosuspend_delay_ms is 0. ulite_runtime_suspend() then disables the
> clock a second time, and after ulite_release() it dereferences the
> cleared drvdata.
>
> Hold a runtime PM reference across ulite_release(), so the device is
> resumed and cannot suspend while the port is torn down. Disable the
> clock after runtime PM is disabled, and only if the device is not
> runtime suspended, then unprepare it.
>
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-uartlite-remove-clk-v2-1-920d6ba90074@mbzuai.ac.ae?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 11:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:09 [PATCH v2] serial: uartlite: Disable the clock after the port is removed Arina Kharlamova via B4 Relay
2026-12-03 11:23 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox