* [PATCH] counter: rz-mtu3-cnt: Fix runtime PM leak in rz_mtu3_count_enable_write()
@ 2026-09-16 9:22 Wentao Liang
2026-09-16 17:38 ` William Breathitt Gray
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-16 9:22 UTC (permalink / raw)
To: biju.das.jz
Cc: lee, linux-iio, linux-kernel, linux-renesas-soc, wbg,
Wentao Liang, stable
When enabling a counter, the runtime PM reference taken by
pm_runtime_get_sync() is never dropped if rz_mtu3_initialize_counter()
fails and returns an error, e.g. -EBUSY when the channel is already
requested. Because priv->count_is_enabled[] is left false, a subsequent
disable write also takes the early exit path, so the reference is never
recovered. Additionally, if pm_runtime_get_sync() itself fails the
device usage count is left incremented while the hardware is still
accessed with runtime PM suspended.
Use pm_runtime_resume_and_get() to resume the device and bail out if it
fails, and drop the runtime PM reference when
rz_mtu3_initialize_counter() fails.
Fixes: 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/counter/rz-mtu3-cnt.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c
index 7bfb6979193c..2bfc92bea757 100644
--- a/drivers/counter/rz-mtu3-cnt.c
+++ b/drivers/counter/rz-mtu3-cnt.c
@@ -504,10 +504,15 @@ static int rz_mtu3_count_enable_write(struct counter_device *counter,
goto exit;
if (enable) {
- pm_runtime_get_sync(counter->parent);
+ ret = pm_runtime_resume_and_get(counter->parent);
+ if (ret)
+ goto exit;
+
ret = rz_mtu3_initialize_counter(counter, count->id);
if (ret == 0)
priv->count_is_enabled[count->id] = true;
+ else
+ pm_runtime_put(counter->parent);
} else {
rz_mtu3_terminate_counter(counter, count->id);
priv->count_is_enabled[count->id] = false;
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] counter: rz-mtu3-cnt: Fix runtime PM leak in rz_mtu3_count_enable_write()
2026-09-16 9:22 [PATCH] counter: rz-mtu3-cnt: Fix runtime PM leak in rz_mtu3_count_enable_write() Wentao Liang
@ 2026-09-16 17:38 ` William Breathitt Gray
0 siblings, 0 replies; 2+ messages in thread
From: William Breathitt Gray @ 2026-09-16 17:38 UTC (permalink / raw)
To: Wentao Liang
Cc: William Breathitt Gray, biju.das.jz, lee, linux-iio,
linux-kernel, linux-renesas-soc, stable
On Wed, Sep 16, 2026 at 09:22:42AM +0000, Wentao Liang wrote:
> When enabling a counter, the runtime PM reference taken by
> pm_runtime_get_sync() is never dropped if rz_mtu3_initialize_counter()
> fails and returns an error, e.g. -EBUSY when the channel is already
> requested. Because priv->count_is_enabled[] is left false, a subsequent
> disable write also takes the early exit path, so the reference is never
> recovered. Additionally, if pm_runtime_get_sync() itself fails the
> device usage count is left incremented while the hardware is still
> accessed with runtime PM suspended.
>
> Use pm_runtime_resume_and_get() to resume the device and bail out if it
> fails, and drop the runtime PM reference when
> rz_mtu3_initialize_counter() fails.
>
> Fixes: 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> drivers/counter/rz-mtu3-cnt.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c
> index 7bfb6979193c..2bfc92bea757 100644
> --- a/drivers/counter/rz-mtu3-cnt.c
> +++ b/drivers/counter/rz-mtu3-cnt.c
> @@ -504,10 +504,15 @@ static int rz_mtu3_count_enable_write(struct counter_device *counter,
> goto exit;
>
> if (enable) {
> - pm_runtime_get_sync(counter->parent);
> + ret = pm_runtime_resume_and_get(counter->parent);
> + if (ret)
> + goto exit;
> +
> ret = rz_mtu3_initialize_counter(counter, count->id);
> if (ret == 0)
> priv->count_is_enabled[count->id] = true;
> + else
> + pm_runtime_put(counter->parent);
> } else {
> rz_mtu3_terminate_counter(counter, count->id);
> priv->count_is_enabled[count->id] = false;
> --
> 2.34.1
>
Hello Wentao,
This looks like an earlier patch submission we've received.[^1] In fact,
I wonder whether these patches will be necessary anymore if the
"counter: rz-mtu3-cnt: check clock and runtime PM errors" series is
merged.[^2]
Sincerely,
William Breathitt Gray
[^1]: https://lore.kernel.org/all/20260814134138.1388045-1-ruoyuw560@gmail.com/
[^2]: https://lore.kernel.org/all/20260903090719.3498955-1-dayou5941@163.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-16 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 9:22 [PATCH] counter: rz-mtu3-cnt: Fix runtime PM leak in rz_mtu3_count_enable_write() Wentao Liang
2026-09-16 17:38 ` William Breathitt Gray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®