1
0
Fork 0

PM / OPP: Fix shared OPP table support in dev_pm_opp_set_prop_name()

It should be fine to call dev_pm_opp_set_prop_name() for all possible
CPUs, even if some of them share the OPP table as the caller may not be
aware of sharing policy.

Lets increment the reference count of the OPP table and return its
pointer. The caller need to call dev_pm_opp_put_prop_name() the same
number of times later on to drop all the references.

To avoid adding another counter to count how many times
dev_pm_opp_set_prop_name() is called for the same OPP table,
dev_pm_opp_put_prop_name() frees the resources on the very first call
made to it, assuming that the caller would be calling it sequentially
for all the CPUs. We can revisit that if that assumption is broken in
the future.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
hifive-unleashed-5.1
Viresh Kumar 2018-05-22 16:38:08 +05:30
parent 25419de1b8
commit 878ec1a9f0
1 changed files with 5 additions and 20 deletions

View File

@ -1216,7 +1216,6 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
{
struct opp_table *opp_table;
int ret;
opp_table = dev_pm_opp_get_opp_table(dev);
if (!opp_table)
@ -1225,26 +1224,17 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
/* Make sure there are no concurrent readers while updating opp_table */
WARN_ON(!list_empty(&opp_table->opp_list));
/* Do we already have a prop-name associated with opp_table? */
if (opp_table->prop_name) {
dev_err(dev, "%s: Already have prop-name %s\n", __func__,
opp_table->prop_name);
ret = -EBUSY;
goto err;
}
/* Another CPU that shares the OPP table has set the property ? */
if (opp_table->prop_name)
return opp_table;
opp_table->prop_name = kstrdup(name, GFP_KERNEL);
if (!opp_table->prop_name) {
ret = -ENOMEM;
goto err;
dev_pm_opp_put_opp_table(opp_table);
return ERR_PTR(-ENOMEM);
}
return opp_table;
err:
dev_pm_opp_put_opp_table(opp_table);
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
@ -1261,11 +1251,6 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
/* Make sure there are no concurrent readers while updating opp_table */
WARN_ON(!list_empty(&opp_table->opp_list));
if (!opp_table->prop_name) {
pr_err("%s: Doesn't have a prop-name\n", __func__);
return;
}
kfree(opp_table->prop_name);
opp_table->prop_name = NULL;