* @triggered_count: Number of times this reset line has been reset. Currently
* only used for shared resets, which means that the value
* will be either 0 or 1.
+ * @lock: serializes the internals of reset_control_acquire()
*/
struct reset_control {
struct reset_controller_dev __rcu *rcdev;
bool array;
atomic_t deassert_count;
atomic_t triggered_count;
+ struct mutex lock;
};
/**
if (reset_control_is_array(rstc))
return reset_control_array_acquire(rstc_to_array(rstc));
- guard(mutex)(&reset_list_mutex);
+ guard(mutex)(&rstc->lock);
if (rstc->acquired)
return 0;
list_add(&rstc->list, &rcdev->reset_control_head);
rstc->id = index;
kref_init(&rstc->refcnt);
+ mutex_init(&rstc->lock);
rstc->acquired = acquired;
rstc->shared = shared;
get_device(rcdev->dev);
refcnt);
struct reset_controller_dev *rcdev;
- lockdep_assert_held(&reset_list_mutex);
+ lockdep_assert_held(&rstc->srcu);
- scoped_guard(srcu, &rstc->srcu) {
- rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true);
- if (rcdev) {
- guard(mutex)(&rcdev->lock);
- reset_controller_remove(rcdev, rstc);
- }
+ rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true);
+ if (rcdev) {
+ lockdep_assert_held(&rcdev->lock);
+ reset_controller_remove(rcdev, rstc);
}
- synchronize_srcu(&rstc->srcu);
- cleanup_srcu_struct(&rstc->srcu);
- kfree(rstc);
+ mutex_destroy(&rstc->lock);
}
-static void __reset_control_put_internal(struct reset_control *rstc)
+static void reset_control_put_internal(struct reset_control *rstc)
{
- lockdep_assert_held(&reset_list_mutex);
+ struct reset_controller_dev *rcdev;
+ int ret = 0;
if (IS_ERR_OR_NULL(rstc))
return;
- kref_put(&rstc->refcnt, __reset_control_release);
+ 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 (ret) {
+ synchronize_srcu(&rstc->srcu);
+ cleanup_srcu_struct(&rstc->srcu);
+ kfree(rstc);
+ }
}
static void reset_gpio_aux_device_release(struct device *dev)
{
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
bool gpio_fallback = false;
- struct reset_control *rstc;
+ struct reset_control *rstc = ERR_PTR(-EINVAL);
struct reset_controller_dev *rcdev;
struct of_phandle_args args;
int rstc_id;
flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;
- /* reset_list_mutex also protects the rcdev's reset_control list */
- rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
+ scoped_guard(mutex, &rcdev->lock)
+ rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
out_put:
of_node_put(args.np);
return 0;
err:
- guard(mutex)(&reset_list_mutex);
-
while (i--)
- __reset_control_put_internal(rstcs[i].rstc);
+ reset_control_put_internal(rstcs[i].rstc);
return ret;
}
{
int i;
- guard(mutex)(&reset_list_mutex);
-
for (i = 0; i < resets->num_rstcs; i++)
- __reset_control_put_internal(resets->rstc[i]);
+ reset_control_put_internal(resets->rstc[i]);
kfree(resets);
}
return;
}
- guard(mutex)(&reset_list_mutex);
-
- __reset_control_put_internal(rstc);
+ reset_control_put_internal(rstc);
}
EXPORT_SYMBOL_GPL(reset_control_put);
*/
void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs)
{
- guard(mutex)(&reset_list_mutex);
-
while (num_rstcs--)
- __reset_control_put_internal(rstcs[num_rstcs].rstc);
+ reset_control_put_internal(rstcs[num_rstcs].rstc);
}
EXPORT_SYMBOL_GPL(reset_control_bulk_put);
return &resets->base;
err_rst:
- guard(mutex)(&reset_list_mutex);
-
while (--i >= 0)
- __reset_control_put_internal(resets->rstc[i]);
+ reset_control_put_internal(resets->rstc[i]);
kfree(resets);