]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/opp/core.c
Merge tag 'printk-for-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek...
[linux.git] / drivers / opp / core.c
index d3e33fd326948380d1b06823c9323c1e676579d5..2c2df4e4fc14db27e6d2f5f938ff6300e43e9412 100644 (file)
@@ -318,7 +318,7 @@ int dev_pm_opp_get_opp_count(struct device *dev)
                count = PTR_ERR(opp_table);
                dev_dbg(dev, "%s: OPP table not found (%d)\n",
                        __func__, count);
-               return 0;
+               return count;
        }
 
        count = _get_opp_count(opp_table);
@@ -759,8 +759,8 @@ static void _remove_opp_dev(struct opp_device *opp_dev,
        kfree(opp_dev);
 }
 
-struct opp_device *_add_opp_dev(const struct device *dev,
-                               struct opp_table *opp_table)
+static struct opp_device *_add_opp_dev_unlocked(const struct device *dev,
+                                               struct opp_table *opp_table)
 {
        struct opp_device *opp_dev;
        int ret;
@@ -772,7 +772,6 @@ struct opp_device *_add_opp_dev(const struct device *dev,
        /* Initialize opp-dev */
        opp_dev->dev = dev;
 
-       mutex_lock(&opp_table->lock);
        list_add(&opp_dev->node, &opp_table->dev_list);
 
        /* Create debugfs entries for the opp_table */
@@ -780,6 +779,17 @@ struct opp_device *_add_opp_dev(const struct device *dev,
        if (ret)
                dev_err(dev, "%s: Failed to register opp debugfs (%d)\n",
                        __func__, ret);
+
+       return opp_dev;
+}
+
+struct opp_device *_add_opp_dev(const struct device *dev,
+                               struct opp_table *opp_table)
+{
+       struct opp_device *opp_dev;
+
+       mutex_lock(&opp_table->lock);
+       opp_dev = _add_opp_dev_unlocked(dev, opp_table);
        mutex_unlock(&opp_table->lock);
 
        return opp_dev;
@@ -844,6 +854,15 @@ static struct opp_table *_opp_get_opp_table(struct device *dev, int index)
        if (!IS_ERR(opp_table))
                goto unlock;
 
+       opp_table = _managed_opp(dev, index);
+       if (opp_table) {
+               if (!_add_opp_dev_unlocked(dev, opp_table)) {
+                       dev_pm_opp_put_opp_table(opp_table);
+                       opp_table = NULL;
+               }
+               goto unlock;
+       }
+
        opp_table = _allocate_opp_table(dev, index);
 
 unlock: