]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
PM / OPP: Fix shared OPP table support in dev_pm_opp_register_set_opp_helper()
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 22 May 2018 11:08:08 +0000 (16:38 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Tue, 22 May 2018 11:30:10 +0000 (17:00 +0530)
It should be fine to call dev_pm_opp_register_set_opp_helper() 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_register_put_opp_helper()
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_register_set_opp_helper() is called for the same OPP table,
dev_pm_opp_register_put_opp_helper() 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>
drivers/opp/core.c

index 780c89a49d1816094a771be7d2eca24efa8242c8..ab2f3fead6b1ceee55b0ced767dafdacb1202b35 100644 (file)
@@ -1477,7 +1477,6 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
                        int (*set_opp)(struct dev_pm_set_opp_data *data))
 {
        struct opp_table *opp_table;
-       int ret;
 
        if (!set_opp)
                return ERR_PTR(-EINVAL);
@@ -1488,24 +1487,15 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
 
        /* This should be called before OPPs are initialized */
        if (WARN_ON(!list_empty(&opp_table->opp_list))) {
-               ret = -EBUSY;
-               goto err;
-       }
-
-       /* Already have custom set_opp helper */
-       if (WARN_ON(opp_table->set_opp)) {
-               ret = -EBUSY;
-               goto err;
+               dev_pm_opp_put_opp_table(opp_table);
+               return ERR_PTR(-EBUSY);
        }
 
-       opp_table->set_opp = set_opp;
+       /* Another CPU that shares the OPP table has set the helper ? */
+       if (!opp_table->set_opp)
+               opp_table->set_opp = set_opp;
 
        return opp_table;
-
-err:
-       dev_pm_opp_put_opp_table(opp_table);
-
-       return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
 
@@ -1518,17 +1508,10 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
  */
 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
 {
-       if (!opp_table->set_opp) {
-               pr_err("%s: Doesn't have custom set_opp helper set\n",
-                      __func__);
-               return;
-       }
-
        /* Make sure there are no concurrent readers while updating opp_table */
        WARN_ON(!list_empty(&opp_table->opp_list));
 
        opp_table->set_opp = NULL;
-
        dev_pm_opp_put_opp_table(opp_table);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);