[PATCH 1/2] reset: Fix reset_control leak when put after controller unregister
From: Tzung-Bi Shih
Date: Mon Nov 02 2026 - 15:37:35 EST
After commit 8c91302a29bc ("reset: protect struct reset_control with its
own mutex"), reset_control_put_internal() returns early if `rcdev` is
NULL.
When a reset controller is unregistered while consumers still hold
reset_control handles, reset_controller_unregister() sets `rstc->rcdev`
to NULL. When consumers later release their handles via
reset_control_put(), the early return skips kref_put(), resulting in
leaking resources.
Call kref_put() in reset_control_put_internal() even if `rcdev` is NULL.
Fixes: 8c91302a29bc ("reset: protect struct reset_control with its own mutex")
Signed-off-by: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
---
drivers/reset/core.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 38e189d04d09..1f6d7ef48a67 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -160,6 +160,8 @@ int reset_controller_register(struct reset_controller_dev *rcdev)
}
EXPORT_SYMBOL_GPL(reset_controller_register);
+static void reset_control_put_internal(struct reset_control *rstc);
+
static void reset_controller_remove(struct reset_controller_dev *rcdev,
struct reset_control *rstc)
{
@@ -185,11 +187,17 @@ void reset_controller_unregister(struct reset_controller_dev *rcdev)
/*
* Numb but don't free the remaining reset control handles that are
* still held by consumers.
+ *
+ * Hold a temporary reference on rstc before clearing rstc->rcdev:
+ * once rstc->rcdev is NULL, a concurrent reset_control_put_internal()
+ * will not acquire rcdev->lock and could otherwise free rstc.
*/
list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) {
+ kref_get(&rstc->refcnt);
rcu_assign_pointer(rstc->rcdev, NULL);
synchronize_srcu(&rstc->srcu);
reset_controller_remove(rcdev, rstc);
+ reset_control_put_internal(rstc);
}
}
@@ -913,12 +921,13 @@ static void reset_control_put_internal(struct reset_control *rstc)
scoped_guard(srcu, &rstc->srcu) {
rcdev = srcu_dereference(rstc->rcdev, &rstc->srcu);
- if (!rcdev)
- /* Already released. */
- return;
-
- guard(mutex)(&rcdev->lock);
- ret = kref_put(&rstc->refcnt, __reset_control_release);
+ if (rcdev) {
+ guard(mutex)(&rcdev->lock);
+ ret = kref_put(&rstc->refcnt, __reset_control_release);
+ } else {
+ /* Already detached from rcdev. */
+ ret = kref_put(&rstc->refcnt, __reset_control_release);
+ }
}
if (ret) {
--
2.53.0