Re: [PATCH] opp: Invalidate current opp when draining the opp list

From: Viresh Kumar
Date: Mon Mar 08 2021 - 23:32:33 EST


On 08-03-21, 18:14, Beata Michalska wrote:
> > -bool _opp_remove_all_static(struct opp_table *opp_table)
> > +/*
> > + * Can't remove the OPP from under the lock, debugfs removal needs to happen
> > + * lock less to avoid circular dependency issues. This must be called without
> > + * the opp_table->lock held.
> > + */
> > +static int _opp_drain_list(struct opp_table *opp_table, bool dynamic)
> > {
> > - struct dev_pm_opp *opp;
> > + struct dev_pm_opp *opp, *current_opp = NULL;
> > + int count = 0;
> > +
> > + while ((opp = _opp_get_next(opp_table, dynamic))) {
> > + if (opp_table->current_opp == opp) {
> > + /*
> > + * Reached at current OPP twice, no other OPPs left. The
> > + * last reference to current_opp is dropped from
> > + * _opp_table_kref_release().
> > + */
> > + if (current_opp)
> > + break;
> > +
> > + current_opp = opp;
> > + }
> Having a quick look at the code ...
> Shouldn't the current_opp be moved at the end of the list ?
> Otherwise there is a risk of leaving unreferenced opps (and opp_table).

How exactly ? Note that it is expected that the OPP table isn't being
used by anyone anymore at this point and all the users went away.

> Might be also worth adding warning (?)
>
> WARN_ONCE(!list_is_singular())

It is allowed for the list to contain both static and dynamic OPPs,
and so the list may have more OPPs here.

--
viresh