* [PATCH] rtc: meson: fix refcount leak in meson_rtc_get_bus
@ 2026-06-11 3:56 WenTao Liang
2026-06-11 8:08 ` Philipp Zabel
0 siblings, 1 reply; 3+ messages in thread
From: WenTao Liang @ 2026-06-11 3:56 UTC (permalink / raw)
To: alexandre.belloni, neil.armstrong, khilman, p.zabel
Cc: jbrunet, martin.blumenstingl, ben.dooks, linux-rtc,
linux-arm-kernel, linux-amlogic, linux-kernel, WenTao Liang,
stable
In meson_rtc_get_bus(), reset_control_reset() is called to trigger
a hardware reset when the serial bus is not ready. The function may
retry up to three times, but neither the successful nor the failure
path calls reset_control_rearm() to balance the reference count,
leaking the triggered_count on shared reset controls.
Fix this by adding reset_control_rearm() after reset_control_reset()
on both the error return path and the success path within the retry
loop, ensuring the reset control can be re-triggered on subsequent
bus acquisition attempts.
Cc: stable@vger.kernel.org
Fixes: d8fe6009aa3e ("rtc: support for the Amlogic Meson RTC")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
drivers/rtc/rtc-meson.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-meson.c b/drivers/rtc/rtc-meson.c
index 21eceb9e2e13..729384dceb12 100644
--- a/drivers/rtc/rtc-meson.c
+++ b/drivers/rtc/rtc-meson.c
@@ -146,8 +146,12 @@ static int meson_rtc_get_bus(struct meson_rtc *rtc)
dev_warn(rtc->dev, "failed to get bus, resetting RTC\n");
ret = reset_control_reset(rtc->reset);
- if (ret)
+ if (ret) {
+ reset_control_rearm(rtc->reset);
return ret;
+ }
+
+ reset_control_rearm(rtc->reset);
}
dev_err(rtc->dev, "bus is not ready\n");
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] rtc: meson: fix refcount leak in meson_rtc_get_bus
2026-06-11 3:56 [PATCH] rtc: meson: fix refcount leak in meson_rtc_get_bus WenTao Liang
@ 2026-06-11 8:08 ` Philipp Zabel
0 siblings, 0 replies; 3+ messages in thread
From: Philipp Zabel @ 2026-06-11 8:08 UTC (permalink / raw)
To: WenTao Liang
Cc: alexandre.belloni, neil.armstrong, khilman, jbrunet,
martin.blumenstingl, ben.dooks, linux-rtc, linux-arm-kernel,
linux-amlogic, linux-kernel, stable
On Thu, Jun 11, 2026 at 11:56:05AM +0800, WenTao Liang wrote:
> In meson_rtc_get_bus(), reset_control_reset() is called to trigger
> a hardware reset when the serial bus is not ready. The function may
> retry up to three times, but neither the successful nor the failure
> path calls reset_control_rearm() to balance the reference count,
> leaking the triggered_count on shared reset controls.
Wrong, this driver uses exclusive reset control, which does not do any
refcounting. Arguably, it should request the reset control via
devm_regulator_get_exclusive() instead of devm_regulator_get() to
make this clear.
> Fix this by adding reset_control_rearm() after reset_control_reset()
> on both the error return path and the success path within the retry
> loop, ensuring the reset control can be re-triggered on subsequent
> bus acquisition attempts.
This doesn't fix anything, reset_control_rearm() does nothing and
should not be used with exclusive reset controls.
regards
Philipp
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] rtc: meson: fix refcount leak in meson_rtc_get_bus
@ 2026-06-11 3:40 WenTao Liang
0 siblings, 0 replies; 3+ messages in thread
From: WenTao Liang @ 2026-06-11 3:40 UTC (permalink / raw)
To: alexandre.belloni
Cc: neil.armstrong, khilman, jbrunet, martin.blumenstingl, p.zabel,
ben.dooks, linux-rtc, linux-arm-kernel, linux-amlogic,
linux-kernel, WenTao Liang, stable
In meson_rtc_get_bus(), reset_control_reset() is called to trigger
a hardware reset when the serial bus is not ready. The function may
retry up to three times, but neither the successful nor the failure
path calls reset_control_rearm() to balance the reference count,
leaking the triggered_count on shared reset controls.
Fix this by adding reset_control_rearm() after reset_control_reset()
on both the error return path and the success path within the retry
loop, ensuring the reset control can be re-triggered on subsequent
bus acquisition attempts.
Cc: stable@vger.kernel.org
Fixes: d8fe6009aa3e ("rtc: support for the Amlogic Meson RTC")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
drivers/rtc/rtc-meson.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-meson.c b/drivers/rtc/rtc-meson.c
index 21eceb9e2e13..729384dceb12 100644
--- a/drivers/rtc/rtc-meson.c
+++ b/drivers/rtc/rtc-meson.c
@@ -146,8 +146,12 @@ static int meson_rtc_get_bus(struct meson_rtc *rtc)
dev_warn(rtc->dev, "failed to get bus, resetting RTC\n");
ret = reset_control_reset(rtc->reset);
- if (ret)
+ if (ret) {
+ reset_control_rearm(rtc->reset);
return ret;
+ }
+
+ reset_control_rearm(rtc->reset);
}
dev_err(rtc->dev, "bus is not ready\n");
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-11 8:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 3:56 [PATCH] rtc: meson: fix refcount leak in meson_rtc_get_bus WenTao Liang
2026-06-11 8:08 ` Philipp Zabel
-- strict thread matches above, loose matches on Subject: below --
2026-06-11 3:40 WenTao Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox