[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260105-reset-core-refactor-v1-10-ac443103498d@oss.qualcomm.com>
Date: Mon, 05 Jan 2026 15:15:29 +0100
From: Bartosz Golaszewski <bartosz.golaszewski@....qualcomm.com>
To: Krzysztof Kozlowski <krzk@...nel.org>,
Philipp Zabel <p.zabel@...gutronix.de>
Cc: linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@....qualcomm.com>
Subject: [PATCH 10/15] reset: protect struct reset_controller_dev with its
own mutex
Currently we use a single, global mutex - misleadingly names
reset_list_mutex - to protect the global list of reset devices,
per-controller list of reset control handles and also internal fields of
struct reset_control. Locking can be made a lot more fine-grained if we
use a separate mutex for serializing operations on the list AND
accessing the reset controller device.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@....qualcomm.com>
---
drivers/reset/core.c | 44 ++++++++++++++++++++++++----------------
include/linux/reset-controller.h | 3 +++
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index a7992b8ad1c1fbd974d221544da00d4ab3938f70..a53d445fbbfc4601c062e7e5f17278417bd37836 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -131,6 +131,7 @@ int reset_controller_register(struct reset_controller_dev *rcdev)
}
INIT_LIST_HEAD(&rcdev->reset_control_head);
+ mutex_init(&rcdev->lock);
guard(mutex)(&reset_list_mutex);
@@ -143,6 +144,8 @@ EXPORT_SYMBOL_GPL(reset_controller_register);
static void reset_controller_remove(struct reset_controller_dev *rcdev,
struct reset_control *rstc)
{
+ lockdep_assert_held(&rcdev->lock);
+
list_del(&rstc->list);
module_put(rcdev->owner);
put_device(rcdev->dev);
@@ -156,19 +159,22 @@ void reset_controller_unregister(struct reset_controller_dev *rcdev)
{
struct reset_control *rstc, *pos;
- guard(mutex)(&reset_list_mutex);
-
- list_del(&rcdev->list);
+ scoped_guard(mutex, &reset_list_mutex)
+ list_del(&rcdev->list);
- /*
- * Numb but don't free the remaining reset control handles that are
- * still held by consumers.
- */
- list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) {
- rcu_assign_pointer(rstc->rcdev, NULL);
- synchronize_srcu(&rstc->srcu);
- reset_controller_remove(rcdev, rstc);
+ scoped_guard(mutex, &rcdev->lock) {
+ /*
+ * Numb but don't free the remaining reset control handles that are
+ * still held by consumers.
+ */
+ list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) {
+ rcu_assign_pointer(rstc->rcdev, NULL);
+ synchronize_srcu(&rstc->srcu);
+ reset_controller_remove(rcdev, rstc);
+ }
}
+
+ mutex_destroy(&rcdev->lock);
}
EXPORT_SYMBOL_GPL(reset_controller_unregister);
@@ -712,10 +718,12 @@ int reset_control_acquire(struct reset_control *rstc)
if (!rcdev)
return -ENODEV;
- list_for_each_entry(rc, &rcdev->reset_control_head, list) {
- if (rstc != rc && rstc->id == rc->id) {
- if (rc->acquired)
- return -EBUSY;
+ scoped_guard(mutex, &rcdev->lock) {
+ list_for_each_entry(rc, &rcdev->reset_control_head, list) {
+ if (rstc != rc && rstc->id == rc->id) {
+ if (rc->acquired)
+ return -EBUSY;
+ }
}
}
@@ -806,7 +814,7 @@ __reset_control_get_internal(struct reset_controller_dev *rcdev,
struct reset_control *rstc;
int ret;
- lockdep_assert_held(&reset_list_mutex);
+ lockdep_assert_held(&rcdev->lock);
/* Expect callers to filter out OPTIONAL and DEASSERTED bits */
if (WARN_ON(flags & ~(RESET_CONTROL_FLAGS_BIT_SHARED |
@@ -868,8 +876,10 @@ static void __reset_control_release(struct kref *kref)
scoped_guard(srcu, &rstc->srcu) {
rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true);
- if (rcdev)
+ if (rcdev) {
+ guard(mutex)(&rcdev->lock);
reset_controller_remove(rcdev, rstc);
+ }
}
synchronize_srcu(&rstc->srcu);
diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h
index aa95b460fdf86f10002a465e285cd0119da6eeaf..2fecb4edeba1a2b1f5f5db2b34c867362c5f9c18 100644
--- a/include/linux/reset-controller.h
+++ b/include/linux/reset-controller.h
@@ -3,6 +3,7 @@
#define _LINUX_RESET_CONTROLLER_H_
#include <linux/list.h>
+#include <linux/mutex.h>
struct reset_controller_dev;
@@ -40,6 +41,7 @@ struct of_phandle_args;
* device tree to id as given to the reset control ops, defaults
* to :c:func:`of_reset_simple_xlate`.
* @nr_resets: number of reset controls in this reset controller device
+ * @lock: synchronizes concurrent access to the structure's fields
*/
struct reset_controller_dev {
const struct reset_control_ops *ops;
@@ -52,6 +54,7 @@ struct reset_controller_dev {
int (*of_xlate)(struct reset_controller_dev *rcdev,
const struct of_phandle_args *reset_spec);
unsigned int nr_resets;
+ struct mutex lock;
};
#if IS_ENABLED(CONFIG_RESET_CONTROLLER)
--
2.47.3
Powered by blists - more mailing lists