Re: [PATCH v15 4/4] reset: Leverage revocable for accessing struct reset_controller_dev
From: Tzung-Bi Shih
Date: Tue Dec 01 2026 - 08:06:28 EST
On Mon, Nov 02, 2026 at 07:02:40PM +0100, Philipp Zabel wrote:
> On Di, 2026-11-03 at 00:17 +0800, Tzung-Bi Shih wrote:
> > static void reset_controller_remove(struct reset_controller_dev *rcdev,
> > struct reset_control *rstc)
> > {
> > lockdep_assert_held(&rcdev->lock);
> >
> > - list_del(&rstc->list);
> > + /*
> > + * reset_control_put_internal() may observe a non-NULL rcdev before
> > + * revocable_revoke() runs, and then wait on rcdev->lock while
> > + * reset_controller_unregister() already detaches rstc.
> > + */
> > + if (list_empty(&rstc->list))
> > + return;
> > + list_del_init(&rstc->list);
> > +
>
> See also what I said about the fix series. If this were split into
> list_del() and module_put()/put/device() parts already, this wouldn't
> be necessary.
Dropped in v16[1]: reset_controller_unregister() moves rstc to the local
list (with kref_get()) under rcdev->lock before revocable_revoke(), so
reset_controller_remove() is only called once.
> > @@ -909,17 +873,9 @@ static void __reset_control_release(struct kref *kref)
> > {
> > struct reset_control *rstc = container_of(kref, struct reset_control,
> > refcnt);
> > - struct reset_controller_dev *rcdev;
> > -
> > - lockdep_assert_held(&rstc->srcu);
> > -
> > - rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true);
> > - if (rcdev) {
> > - lockdep_assert_held(&rcdev->lock);
> > - reset_controller_remove(rcdev, rstc);
> > - }
> >
> > mutex_destroy(&rstc->lock);
> > + revocable_put(rstc->rcdev_revocable);
>
> I think now we can move the kfree(rstc) back in here?
No, we can't. When rstc is still attached to rcdev in
reset_control_put_internal(), reset_controller_remove(...) accesses
rstc->list after kref_put(...) returns 1.
Hopefully this is clearer in v16[1], and we can follow up there.
[1] https://lore.kernel.org/all/20261201130303.14530-5-tzungbi@xxxxxxxxxx