rtc: meson: fix refcount leak in meson_rtc_get_bus
Subsystems (3)
PATCH 1/1 rtc: meson: fix refcount leak in meson_rtc_get_bus
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.
--- drivers/rtc/rtc-meson.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/rtc/rtc-meson.c +5 -1
@@ -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" );
Signature · 1 line
2.50.1 (Apple Git-155)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Bogus fix attempting to fix a non-existent refcount leak, which violates the reset API contract…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Bogus fix attempting to fix a non-existent refcount leak, which violates the reset API contract and introduces a potential counter underflow. --
commit dec7a1c708a5b28d1344bf6fb038df54d6001df3
Author: WenTao Liang <[email protected]>
rtc: meson: fix refcount leak in meson_rtc_get_bus
This commit adds calls to reset_control_rearm() in both the error and success paths of meson_rtc_get_bus() after triggering a reset. The intention is to prevent a triggered_count leak on shared reset controls.
drivers/rtc/rtc-meson.c static int meson_rtc_get_bus(struct meson_rtc *rtc) · line 150
Quoted 11 lines
drivers/rtc/rtc-meson.c +2
-1@@ -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);
[Severity: Medium]
Is this fix applicable to this driver's reset control?
The reset control rtc->reset is acquired as an exclusive control using devm_reset_control_get(). Exclusive controls do not track triggered_count, so calling reset_control_rearm() is a no-op in this context, meaning there was no leak to fix.
Additionally, if this were a shared reset control, would calling reset_control_rearm() on the error path cause a counter underflow?
The reset core already handles the rollback internally by decrementing triggered_count if the underlying reset fails. Adding a manual reset_control_rearm() here on failure would decrement it a second time, which could trigger a WARN_ON() for dropping below zero.
Quoted 7 lines
drivers/rtc/rtc-meson.c +4
-0+return ret; + } + +reset_control_rearm (rtc->reset); }dev_err (rtc->dev,"bus is not ready\n" );
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic