serial: 8250_uniphier: Use devm_clk_get_enabled()
Subsystems (2)
PATCH v2 1/1 serial: 8250_uniphier: Use devm_clk_get_enabled()
uniphier_uart_probe() enables priv->clk by hand and is then responsible for disabling it again on every error path. It misses one: when uart_read_port_properties() fails the function returns directly, leaving the clock prepared and enabled. The neighbouring path, taken when serial8250_register_8250_port() fails, does call clk_disable_unprepare(), which shows the leak is an oversight rather than intent.
Rather than adding another manual unwind, switch to devm_clk_get_enabled() so the clock is released by devres. That removes the error path entirely, along with the explicit disables in the register failure path and in uniphier_uart_remove().
The clock is still disabled and re-enabled by hand across system sleep, which stays balanced: only SET_SYSTEM_SLEEP_PM_OPS is used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach.
Found by smatch:
drivers/tty/serial/8250/8250_uniphier.c:232 uniphier_uart_probe() warn: 'priv->clk' from clk_prepare_enable() not released on lines: 205.
---
Changes in v2:
- Use devm_clk_get_enabled() instead of adding a clk_disable_unprepare() to the failing path, as suggested in review. This also lets the explicit disables in the serial8250_register_8250_port() error path and in uniphier_uart_remove() go away.
- Reworded the commit message accordingly.
drivers/tty/serial/8250/8250_uniphier.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250_uniphier.c +2 -8
@@ -180,16 +180,12 @@ static int uniphier_uart_probe(struct platform_device *pdev)memset (&up,0 ,sizeof (up)); - priv->clk =devm_clk_get (dev,NULL ); + priv->clk =devm_clk_get_enabled (dev,NULL );if (IS_ERR (priv->clk)) { -dev_err (dev,"failed to get clock\n" ); +dev_err (dev,"failed to get and enable clock\n" );return PTR_ERR (priv->clk); } - ret =clk_prepare_enable (priv->clk); -if (ret) -return ret; - up.port.uartclk =clk_get_rate (priv->clk);spin_lock_init (&priv->atomic_write_lock);
@@ -222,7 +218,6 @@ static int uniphier_uart_probe(struct platform_device *pdev) ret =serial8250_register_8250_port (&up);if (ret <0 ) {dev_err (dev,"failed to register 8250 port\n" ); -clk_disable_unprepare (priv->clk);return ret; } priv->line = ret;
@@ -237,7 +232,6 @@ static void uniphier_uart_remove(struct platform_device *pdev)struct uniphier8250_priv *priv =platform_get_drvdata (pdev);serial8250_unregister_port (priv->line); -clk_disable_unprepare (priv->clk); }static int __maybe_unused uniphier_uart_suspend (struct device *dev)
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
uniphier_uart_probe()enablespriv->clkby hand and is then responsible for disabling it again on every error path. It misses one: whenuart_read_port_properties()fails the function returns directly, leaving the clock prepared and enabled. The neighbouring path, taken whenserial8250_register_8250_port()fails, does callclk_disable_unprepare(), which shows the leak is an oversight rather than intent.Rather than adding another manual unwind, switch to
devm_clk_get_enabled()so the clock is released by devres. That removes the error path entirely, along with the explicit disables in the register failure path and inuniphier_uart_remove().The clock is still disabled and re-enabled by hand across system sleep, which stays balanced: only
SET_SYSTEM_SLEEP_PM_OPSis used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach.
Quoted 6 lines
Found by smatch:
drivers/tty/serial/8250/8250_uniphier.c:232uniphier_uart_probe()warn: 'priv->clk' fromclk_prepare_enable()not released on lines: 205.Fixes 26e8349c0d76 ("serial: 8250_uniphier: Switch to use uart_read_port_properties()")Signed-off-by Malathi A <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 12 lines · Malathi A
uniphier_uart_probe()enablespriv->clkby hand and is then responsible for disabling it again on every error path. It misses one: whenuart_read_port_properties()fails the function returns directly, leaving the clock prepared and enabled. The neighbouring path, taken whenserial8250_register_8250_port()fails, does callclk_disable_unprepare(), which shows the leak is an oversight rather than intent.Rather than adding another manual unwind, switch to
devm_clk_get_enabled()so the clock is released by devres. That removes the error path entirely, along with the explicit disables in the register failure path and inuniphier_uart_remove().
Quoted 8 lines
The clock is still disabled and re-enabled by hand across system sleep, which stays balanced: only
SET_SYSTEM_SLEEP_PM_OPSis used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach.Found by smatch:
drivers/tty/serial/8250/8250_uniphier.c:232uniphier_uart_probe()warn: 'priv->clk' fromclk_prepare_enable()not released on lines: 205.
...
drivers/tty/serial/8250/8250_uniphier.c static int uniphier_uart_probe(struct platform_device *pdev) · line 186
Quoted 6 lines
drivers/tty/serial/8250/8250_uniphier.c +2
-2- priv->clk =devm_clk_get (dev,NULL ); + priv->clk =devm_clk_get_enabled (dev,NULL );if (IS_ERR (priv->clk)) { -dev_err (dev,"failed to get clock\n" ); +dev_err (dev,"failed to get and enable clock\n" );return PTR_ERR (priv->clk);
Consider fixing another latent bug here, id est with intermittent probe defer this will spam the kernel dmesg a lot, so converting to use dev_err_probe() will fix the issue (but at the same time you may convert all of the error messages in probe to use return dev_err_probe() pattern). This needs to be a separate change.
Quoted 1 line
}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kunihiko Hayashi
maintainerHi Malathi,
Quoted 78 lines · Malathi A
uniphier_uart_probe()enablespriv->clkby hand and is then responsible for disabling it again on every error path. It misses one: whenuart_read_port_properties()fails the function returns directly, leaving the clock prepared and enabled. The neighbouring path, taken whenserial8250_register_8250_port()fails, does callclk_disable_unprepare(), which shows the leak is an oversight rather than intent.Rather than adding another manual unwind, switch to
devm_clk_get_enabled()so the clock is released by devres. That removes the error path entirely, along with the explicit disables in the register failure path and inuniphier_uart_remove().The clock is still disabled and re-enabled by hand across system sleep, which stays balanced: only
SET_SYSTEM_SLEEP_PM_OPSis used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach.Found by smatch:
drivers/tty/serial/8250/8250_uniphier.c:232 uniphier_uart_probe() warn:'
priv->clk' fromclk_prepare_enable()not released on lines: 205.Fixes 26e8349c0d76 ("serial: 8250_uniphier: Switch to use
uart_read_port_properties()")Signed-off-by Malathi A <[email protected]>---
Changes in v2:
- Usedevm_clk_get_enabled()instead of adding aclk_disable_unprepare()to the failing path, as suggested in review. This also lets the explicit disables in theserial8250_register_8250_port()error path and inuniphier_uart_remove()go away.
- Reworded the commit message accordingly.drivers/tty/serial/8250/8250_uniphier.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/tty/serial/8250/8250_uniphier.c +2
-6@@ -180,16 +180,12 @@ static int uniphier_uart_probe(struct platform_device *pdev) memset(&up, 0, sizeof(up)); - priv->clk =devm_clk_get (dev,NULL ); + priv->clk =devm_clk_get_enabled (dev,NULL );if (IS_ERR (priv->clk)) { -dev_err (dev,"failed to get clock\n" ); +dev_err (dev,"failed to get and enable clock\n" );return PTR_ERR (priv->clk); } - ret =clk_prepare_enable (priv->clk); -if (ret) -return ret; - up.port.uartclk =clk_get_rate (priv->clk);spin_lock_init(&priv->atomic_write_lock);drivers/tty/serial/8250/8250_uniphier.c +0
-1@@ -222,7 +218,6 @@ static int uniphier_uart_probe(struct platform_device *pdev) ret =serial8250_register_8250_port (&up);if (ret <0 ) {dev_err (dev,"failed to register 8250 port\n" ); -clk_disable_unprepare (priv->clk);return ret; }priv->line = ret;drivers/tty/serial/8250/8250_uniphier.c +0
-1@@ -237,7 +232,6 @@ static void uniphier_uart_remove(struct platform_device *pdev)struct uniphier8250_priv *priv =platform_get_drvdata (pdev);serial8250_unregister_port (priv->line); -clk_disable_unprepare (priv->clk); }
Quoted 1 line
static int
__maybe_unuseduniphier_uart_suspend(struct device *dev)
I'm a bit concerned about the error path in uniphier_uart_resume(). The clock may have been disabled in uniphier_uart_suspend(), and clk_prepare_enable() can fail when trying to enable it again.
In that case, wouldn't devres try to disable an already disabled clock on detach?
Thank you,
---
Best Regards
Kunihiko Hayashi
Quoted 17 lines · Kunihiko Hayashi
Quoted 16 lines · Malathi A
uniphier_uart_probe()enablespriv->clkby hand and is then responsible for disabling it again on every error path. It misses one: whenuart_read_port_properties()fails the function returns directly, leaving the clock prepared and enabled. The neighbouring path, taken whenserial8250_register_8250_port()fails, does callclk_disable_unprepare(), which shows the leak is an oversight rather than intent.Rather than adding another manual unwind, switch to
devm_clk_get_enabled()so the clock is released by devres. That removes the error path entirely, along with the explicit disables in the register failure path and inuniphier_uart_remove().The clock is still disabled and re-enabled by hand across system sleep, which stays balanced: only
SET_SYSTEM_SLEEP_PM_OPSis used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach.
...
Quoted 6 lines
I'm a bit concerned about the error path in
uniphier_uart_resume(). The clock may have been disabled inuniphier_uart_suspend(), andclk_prepare_enable()can fail when trying to enable it again.In that case, wouldn't devres try to disable an already disabled clock on detach?
Isn't there is a guarantee that the .remove() is called with PM runtime on and get, meaning it's called with the enabled clock? But if not the case, we might use PM runtime force operations (resume and suspend in the respective cases.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kunihiko Hayashi
maintainerQuoted 33 lines · Andy Shevchenko
Quoted 2 lines · Kunihiko Hayashi
Quoted 1 line · Malathi A
uniphier_uart_probe()enablespriv->clkby hand and is thenresponsible
Quoted 2 lines
Quoted 2 lines
for disabling it again on every error path. It misses one: when
uart_read_port_properties()fails the function returns directly,leaving
Quoted 2 lines
Quoted 2 lines
the clock prepared and enabled. The neighbouring path, taken when
serial8250_register_8250_port()fails, does call
clk_disable_unprepare(),Quoted 4 lines
Quoted 4 lines
which shows the leak is an oversight rather than intent.
Rather than adding another manual unwind, switch to
devm_clk_get_enabled()so the clock is released by devres. Thatremoves
Quoted 4 lines
Quoted 4 lines
the error path entirely, along with the explicit disables in the register failure path and in
uniphier_uart_remove().The clock is still disabled and re-enabled by hand across system
sleep,
Quoted 3 lines
Quoted 3 lines
which stays balanced: only
SET_SYSTEM_SLEEP_PM_OPSis used, so the device cannot be unbound while suspended and devres always sees an enabled clock at detach....
Quoted 6 lines
I'm a bit concerned about the error path in
uniphier_uart_resume(). The clock may have been disabled inuniphier_uart_suspend(), andclk_prepare_enable()can fail when trying to enable it again.In that case, wouldn't devres try to disable an already disabled clock on detach?
Quoted 7 lines
Isn't there is a guarantee that the .remove() is called with PM runtime on and
get, meaning it's called with the enabled clock? But if not the case, we might
use PM runtime force operations (resume and suspend in the respective cases.
My concern was just the case where clk_prepare_enable() in the system resume callback fails, leaving the clock disabled before devres cleanup.
This driver currently only uses SET_SYSTEM_SLEEP_PM_OPS(), so I wasn't considering runtime PM here.
I don't have a strong opinion on whether runtime PM should be involved, but if it guarantees that the clock is enabled before .remove(), that would address my concern.
Thank you,
---
Best Regards
Kunihiko Hayashi
Quoted 3 lines · Kunihiko Hayashi
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kunihiko Hayashi
On 2026/09/17 13:05, Malathi A wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
I'm a bit concerned about the error path in
uniphier_uart_resume(). The clock may have been disabled inuniphier_uart_suspend(), andclk_prepare_enable()can fail when trying to enable it again.In that case, wouldn't devres try to disable an already disabled clock on detach?
Isn't there is a guarantee that the .remove() is called with PM runtime on
After reading a code of driver core I see that this is the opposite actually. The PM runtime might be off.
Quoted 9 lines
Quoted 3 lines
and get, meaning it's called with the enabled clock? But if not the case, we might use PM runtime force operations (resume and suspend in the respective cases.
My concern was just the case where
clk_prepare_enable()in the system resume callback fails, leaving the clock disabled before devres cleanup.This driver currently only uses
SET_SYSTEM_SLEEP_PM_OPS(), so I wasn't considering runtime PM here.
So, in such a case how do you see the scenario when system is resumed (Right? Otherwise we can't do anything, like detaching driver from the device.) and clock is disabled?
Quoted 3 lines
I don't have a strong opinion on whether runtime PM should be involved, but if it guarantees that the clock is enabled before .remove(), that would address my concern.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kunihiko Hayashi
maintainerQuoted 29 lines · Andy Shevchenko
Quoted 3 lines · Kunihiko Hayashi
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kunihiko Hayashi
On 2026/09/17 13:05, Malathi A wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
I'm a bit concerned about the error path in
uniphier_uart_resume(). The clock may have been disabled inuniphier_uart_suspend(), andclk_prepare_enable()can fail when trying to enable it again.In that case, wouldn't devres try to disable an already disabled clock on detach?
Isn't there is a guarantee that the .remove() is called with PM
runtime on
After reading a code of driver core I see that this is the opposite actually.
The PM runtime might be off.Quoted 1 line
Quoted 1 line
and get, meaning it's called with the enabled clock? But if not the
case,
Quoted 6 lines
Quoted 2 lines
we might use PM runtime force operations (resume and suspend in the respective cases.
My concern was just the case where
clk_prepare_enable()in the system resume callback fails, leaving the clock disabled before devres cleanup.
Quoted 8 lines
Quoted 2 lines
This driver currently only uses
SET_SYSTEM_SLEEP_PM_OPS(), so I wasn't considering runtime PM here.So, in such a case how do you see the scenario when system is resumed (Right?
Otherwise we can't do anything, like detaching driver from the device.) and
clock is disabled?
Ah, I understand your point. I was assuming that the driver could later be detached after uniphier_uart_resume() failed, leaving the clock disabled.
If that sequence cannot happen after a failed system resume, then my concern doesn't apply. Thanks for pointing this out.
In that case, I have no further concerns about the use of devm_clk_get_enabled() here.
Thank you,
---
Best Regards
Kunihiko Hayashi
Quoted 5 lines · Kunihiko Hayashi
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kunihiko Hayashi
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kunihiko Hayashi
On 2026/09/17 13:05, Malathi A wrote:
...
Quoted 25 lines
Quoted 25 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
I'm a bit concerned about the error path in
uniphier_uart_resume(). The clock may have been disabled inuniphier_uart_suspend(), andclk_prepare_enable()can fail when trying to enable it again.In that case, wouldn't devres try to disable an already disabled clock on detach?
Isn't there is a guarantee that the .remove() is called with PM
runtime on
After reading a code of driver core I see that this is the opposite actually.
The PM runtime might be off.Quoted 1 line
Quoted 1 line
and get, meaning it's called with the enabled clock? But if not the
case,
Quoted 8 lines
Quoted 2 lines
we might use PM runtime force operations (resume and suspend in the respective cases.
My concern was just the case where
clk_prepare_enable()in the system resume callback fails, leaving the clock disabled before devres cleanup.This driver currently only uses
SET_SYSTEM_SLEEP_PM_OPS(), so I wasn't considering runtime PM here.
Quoted 8 lines
Quoted 5 lines
So, in such a case how do you see the scenario when system is resumed (Right?
Otherwise we can't do anything, like detaching driver from the device.) and
clock is disabled?Ah, I understand your point. I was assuming that the driver could later be detached after
uniphier_uart_resume()failed, leaving the clock disabled.
I'm not sure, I don't know if I was right. Can you confirm that this scenario is not possible? So, it might look like CPU is resumed, some of the devices were resumed, but this particular UART failed to resume, and now we want to detach it. If this case is possible, I believe tons of the device drivers as of today may be affected by the same issue (it doesn't mean that the issue is impossible to happen, one needs to investigate deeper).
Quoted 2 lines
If that sequence cannot happen after a failed system resume, then my concern doesn't apply.
As pointed out I'm not sure. Last time I experimented with failed resume was long time ago.
Quoted 4 lines
Thanks for pointing this out.
In that case, I have no further concerns about the use of
devm_clk_get_enabled()here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kunihiko Hayashi
maintainerQuoted 18 lines · Andy Shevchenko
Quoted 5 lines · Kunihiko Hayashi
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kunihiko Hayashi
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kunihiko Hayashi
On 2026/09/17 13:05, Malathi A wrote:
...
Quoted 8 lines
Quoted 5 lines
So, in such a case how do you see the scenario when system is resumed (Right?
Otherwise we can't do anything, like detaching driver from the device.) and
clock is disabled?Ah, I understand your point. I was assuming that the driver could later be detached after
uniphier_uart_resume()failed, leaving the clock disabled.
Quoted 6 lines
I'm not sure, I don't know if I was right. Can you confirm that this scenario is not possible? So, it might look like CPU is resumed, some of the devices were resumed, but this particular UART failed to resume, and now we want to detach it. If this case is possible, I believe tons of the device drivers as of today may be affected by the same issue (it doesn't mean that the issue is impossible to happen, one needs to investigate deeper)
Sorry for the delayed reply.
Unfortunately, I can't confirm whether this scenario is impossible. I don't currently have an environment where I can reproduce this system suspend/resume case either.
I agree that if a device can later be detached after its system resume callback has failed, this may affect other drivers using the same pattern as well, and determining that seems to require a deeper look into the PM core behavior.
Quoted 4 lines
Quoted 2 lines
If that sequence cannot happen after a failed system resume, then my concern doesn't apply.
As pointed out I'm not sure. Last time I experimented with failed resume > long time ago.
So I don't have a definitive answer here either, and can only point out this as a potential issue for now.
Thank you,
---
Best Regards
Kunihiko Hayashi