}
INIT_LIST_HEAD(&rcdev->reset_control_head);
+ mutex_init(&rcdev->lock);
guard(mutex)(&reset_list_mutex);
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);
{
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);
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;
+ }
}
}
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 |
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);
#define _LINUX_RESET_CONTROLLER_H_
#include <linux/list.h>
+#include <linux/mutex.h>
struct reset_controller_dev;
* 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: protects the reset control list from concurrent access
*/
struct reset_controller_dev {
const struct reset_control_ops *ops;
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)