Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] serial: uartlite: Resume the device before disabling the clock on remove
@ 2026-12-01 19:19 Arina Kharlamova via B4 Relay
  2026-12-01 19:33 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:19 UTC (permalink / raw)
  To: Peter Korsgaard, Greg Kroah-Hartman, Jiri Slaby, Chuhong Yuan
  Cc: linux-serial, linux-kernel, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

ulite_runtime_suspend() disables the clock, and ulite_remove() calls
clk_disable_unprepare() without looking at the runtime PM state. A
port that is not a console and is not open is runtime suspended after
probe, so unbinding it disables the clock a second time and the clk
core warns "already disabled".

Take a runtime PM reference at the start of ulite_remove(), so the
clock is on when it is disabled and no runtime suspend can run during
the remove, and drop it after runtime PM is disabled.

Fixes: 6a7ce07d6cb7 ("tty: serial: uartlite: use clk_disable_unprepare to match clk_prepare_enable")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
ulite_remove() disables the clock even when the port is runtime
suspended and the clock is already off. The patch resumes the device
first.

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.
---
 drivers/tty/serial/uartlite.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index b9a14dc2f2fd..993569d3432d 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -893,10 +893,12 @@ static void ulite_remove(struct platform_device *pdev)
 	struct uart_port *port = dev_get_drvdata(&pdev->dev);
 	struct uartlite_data *pdata = port->private_data;
 
+	pm_runtime_get_sync(&pdev->dev);
 	clk_disable_unprepare(pdata->clk);
 	ulite_release(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_put_noidle(&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] serial: uartlite: Resume the device before disabling the clock on remove
  2026-12-01 19:19 [PATCH] serial: uartlite: Resume the device before disabling the clock on remove Arina Kharlamova via B4 Relay
@ 2026-12-01 19:33 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 19:33 UTC (permalink / raw)
  To: Arina Kharlamova; +Cc: linux-serial

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] serial: uartlite: clk_disable_unprepare() called before
  ulite_release()
--

commit 61b30e88d1673ed11a94dda9b0b4e0f2531305d8
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

serial: uartlite: Resume the device before disabling the clock on remove

This commit takes a runtime PM reference at the start of ulite_remove() so
that the device is resumed before clk_disable_unprepare() is called, and
drops the reference after disabling runtime PM.

> diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
> index b9a14dc2f2fdf..993569d3432df 100644
> --- a/drivers/tty/serial/uartlite.c
> +++ b/drivers/tty/serial/uartlite.c
> @@ -893,10 +893,12 @@ static void ulite_remove(struct platform_device *pdev)
>  	struct uart_port *port = dev_get_drvdata(&pdev->dev);
>  	struct uartlite_data *pdata = port->private_data;
>  
> +	pm_runtime_get_sync(&pdev->dev);
>  	clk_disable_unprepare(pdata->clk);
>  	ulite_release(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
>  	pm_runtime_set_suspended(&pdev->dev);
> +	pm_runtime_put_noidle(&pdev->dev);
>  	pm_runtime_dont_use_autosuspend(&pdev->dev);
>  }

[Severity: High]
Does calling clk_disable_unprepare(pdata->clk) before ulite_release() and
pm_runtime_disable() disable and unprepare the clock while the UART port is
still active?

When an open port is removed, ulite_startup() holds a second clk_enable()
reference, so clk_disable_unprepare() unprepares a still-enabled clock and
triggers a clk_core_unprepare() warning before ulite_release() ->
uart_remove_one_port() -> ulite_shutdown() accesses ULITE_CONTROL and calls
clk_disable() on the unprepared clock:

drivers/tty/serial/uartlite.c:ulite_shutdown() {
	...
	uart_out32(0, ULITE_CONTROL, port);
	uart_in32(ULITE_CONTROL, port); /* dummy */
	free_irq(port->irq, port);
	clk_disable(pdata->clk);
}

When a closed or console port is removed, clk_disable_unprepare() gates off
the AXI clock before uart_remove_one_port() unregisters the console and
port, so console output during unregistration accesses ULITE registers with
the clock disabled.  Moving clk_disable_unprepare(pdata->clk) after
ulite_release() and pm_runtime_disable() keeps the clock prepared and
enabled until port teardown finishes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-uartlite-remove-clk-v1-1-bdffc49566f6@mbzuai.ac.ae?part=1

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

end of thread, other threads:[~2026-12-01 19:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:19 [PATCH] serial: uartlite: Resume the device before disabling the clock on remove Arina Kharlamova via B4 Relay
2026-12-01 19:33 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox