Skip to content

Commit

Permalink
OPP: Don't drop opp->np reference while it is still in use
Browse files Browse the repository at this point in the history
The struct dev_pm_opp contains a reference of the DT node, opp->np,
throughout its lifetime. We should increase the refcount for the same
from _opp_add_static_v2(), and drop it while removing the OPP finally.

Signed-off-by: Liang He <windhl@126.com>
[ Viresh: Updated subject / commit log, create _of_clear_opp() and drop
	  reference from it]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
  • Loading branch information
Liang He authored and Viresh Kumar committed Jul 19, 2022
1 parent ce736cf commit 3466ea2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ static void _opp_kref_release(struct kref *kref)
* frequency/voltage list.
*/
blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp);
_of_opp_free_required_opps(opp_table, opp);
_of_clear_opp(opp_table, opp);
opp_debug_remove_one(opp);
kfree(opp);
}
Expand Down
12 changes: 9 additions & 3 deletions drivers/opp/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void _of_clear_opp_table(struct opp_table *opp_table)
* Release all resources previously acquired with a call to
* _of_opp_alloc_required_opps().
*/
void _of_opp_free_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp)
static void _of_opp_free_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp)
{
struct dev_pm_opp **required_opps = opp->required_opps;
int i;
Expand All @@ -275,6 +275,12 @@ void _of_opp_free_required_opps(struct opp_table *opp_table,
kfree(required_opps);
}

void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp)
{
_of_opp_free_required_opps(opp_table, opp);
of_node_put(opp->np);
}

/* Populate all required OPPs which are part of "required-opps" list */
static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp)
Expand Down Expand Up @@ -938,7 +944,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,

new_opp->turbo = of_property_read_bool(np, "turbo-mode");

new_opp->np = np;
new_opp->np = of_node_get(np);
new_opp->dynamic = false;
new_opp->available = true;

Expand Down
6 changes: 2 additions & 4 deletions drivers/opp/opp.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,12 @@ static inline bool lazy_linking_pending(struct opp_table *opp_table)
void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index);
void _of_clear_opp_table(struct opp_table *opp_table);
struct opp_table *_managed_opp(struct device *dev, int index);
void _of_opp_free_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp);
void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp);
#else
static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {}
static inline void _of_clear_opp_table(struct opp_table *opp_table) {}
static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; }
static inline void _of_opp_free_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp) {}
static inline void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) {}
#endif

#ifdef CONFIG_DEBUG_FS
Expand Down

0 comments on commit 3466ea2

Please sign in to comment.