Re: [PATCH v2] serial: uartlite: Disable the clock after the port is removed
From: Shubhrajyoti Datta
Date: Fri Dec 04 2026 - 00:57:56 EST
On Thu, Dec 3, 2026 at 4:40 PM Arina Kharlamova via B4 Relay
<devnull+arina.kharlamova.mbzuai.ac.ae@xxxxxxxxxx> wrote:
>
> From: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxx
> ---
> 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);
> }
Minor comment from AI
pm_runtime_get_sync() returns a negative errno on failure but the
return value is not checked. While there's nothing useful to do in a
void remove path, a dev_warn() or a print can be added.
Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxx>
>
> ---
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
> change-id: 20261201-uartlite-remove-clk-9dfc2176f6c9
>
> Best regards,
> --
> Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
>
>
>