]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
PM / OPP: Don't expose srcu_head to register notifiers
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 2 Jan 2017 09:11:03 +0000 (14:41 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 27 Jan 2017 10:49:09 +0000 (11:49 +0100)
Let the OPP core provide helpers to register notifiers for any device,
instead of exposing srcu_head outside of the core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/opp/core.c
drivers/devfreq/devfreq.c
include/linux/pm_opp.h

index 614d779ab6a23cee85f01b02a5a2064eea02343e..f35effad60d1a685a5553291cd43c6fc9192ba89 100644 (file)
@@ -1860,29 +1860,63 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq)
 EXPORT_SYMBOL_GPL(dev_pm_opp_disable);
 
 /**
- * dev_pm_opp_get_notifier() - find notifier_head of the device with opp
- * @dev:       device pointer used to lookup OPP table.
+ * dev_pm_opp_register_notifier() - Register OPP notifier for the device
+ * @dev:       Device for which notifier needs to be registered
+ * @nb:                Notifier block to be registered
  *
- * Return: pointer to  notifier head if found, otherwise -ENODEV or
- * -EINVAL based on type of error casted as pointer. value must be checked
- *  with IS_ERR to determine valid pointer or error result.
+ * Return: 0 on success or a negative error value.
+ */
+int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
+{
+       struct opp_table *opp_table;
+       int ret;
+
+       rcu_read_lock();
+
+       opp_table = _find_opp_table(dev);
+       if (IS_ERR(opp_table)) {
+               ret = PTR_ERR(opp_table);
+               goto unlock;
+       }
+
+       ret = srcu_notifier_chain_register(&opp_table->srcu_head, nb);
+
+unlock:
+       rcu_read_unlock();
+
+       return ret;
+}
+EXPORT_SYMBOL(dev_pm_opp_register_notifier);
+
+/**
+ * dev_pm_opp_unregister_notifier() - Unregister OPP notifier for the device
+ * @dev:       Device for which notifier needs to be unregistered
+ * @nb:                Notifier block to be unregistered
  *
- * Locking: This function must be called under rcu_read_lock(). opp_table is a
- * RCU protected pointer. The reason for the same is that the opp pointer which
- * is returned will remain valid for use with opp_get_{voltage, freq} only while
- * under the locked area. The pointer returned must be used prior to unlocking
- * with rcu_read_unlock() to maintain the integrity of the pointer.
+ * Return: 0 on success or a negative error value.
  */
-struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev)
+int dev_pm_opp_unregister_notifier(struct device *dev,
+                                  struct notifier_block *nb)
 {
-       struct opp_table *opp_table = _find_opp_table(dev);
+       struct opp_table *opp_table;
+       int ret;
 
-       if (IS_ERR(opp_table))
-               return ERR_CAST(opp_table); /* matching type */
+       rcu_read_lock();
+
+       opp_table = _find_opp_table(dev);
+       if (IS_ERR(opp_table)) {
+               ret = PTR_ERR(opp_table);
+               goto unlock;
+       }
+
+       ret = srcu_notifier_chain_unregister(&opp_table->srcu_head, nb);
 
-       return &opp_table->srcu_head;
+unlock:
+       rcu_read_unlock();
+
+       return ret;
 }
-EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier);
+EXPORT_SYMBOL(dev_pm_opp_unregister_notifier);
 
 /*
  * Free OPPs either created using static entries present in DT or even the
index 47206a21bb901f424c4e331c9db6eaedef69d93d..a545c0fee6e165498ec29196d12a9921c43f887f 100644 (file)
@@ -1265,18 +1265,7 @@ EXPORT_SYMBOL(devfreq_recommended_opp);
  */
 int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
 {
-       struct srcu_notifier_head *nh;
-       int ret = 0;
-
-       rcu_read_lock();
-       nh = dev_pm_opp_get_notifier(dev);
-       if (IS_ERR(nh))
-               ret = PTR_ERR(nh);
-       rcu_read_unlock();
-       if (!ret)
-               ret = srcu_notifier_chain_register(nh, &devfreq->nb);
-
-       return ret;
+       return dev_pm_opp_register_notifier(dev, &devfreq->nb);
 }
 EXPORT_SYMBOL(devfreq_register_opp_notifier);
 
@@ -1292,18 +1281,7 @@ EXPORT_SYMBOL(devfreq_register_opp_notifier);
  */
 int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
 {
-       struct srcu_notifier_head *nh;
-       int ret = 0;
-
-       rcu_read_lock();
-       nh = dev_pm_opp_get_notifier(dev);
-       if (IS_ERR(nh))
-               ret = PTR_ERR(nh);
-       rcu_read_unlock();
-       if (!ret)
-               ret = srcu_notifier_chain_unregister(nh, &devfreq->nb);
-
-       return ret;
+       return dev_pm_opp_unregister_notifier(dev, &devfreq->nb);
 }
 EXPORT_SYMBOL(devfreq_unregister_opp_notifier);
 
index 7483ff291a8e72912576c78661ad4efd38b0ecff..66a02deeb03f5b8a125c1242a0fa236f8b3b4550 100644 (file)
@@ -108,7 +108,9 @@ int dev_pm_opp_enable(struct device *dev, unsigned long freq);
 
 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
 
-struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev);
+int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
+int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
+
 int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
                                unsigned int count);
 void dev_pm_opp_put_supported_hw(struct device *dev);
@@ -202,10 +204,14 @@ static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
        return 0;
 }
 
-static inline struct srcu_notifier_head *dev_pm_opp_get_notifier(
-                                                       struct device *dev)
+static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
 {
-       return ERR_PTR(-ENOTSUPP);
+       return -ENOTSUPP;
+}
+
+static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
+{
+       return -ENOTSUPP;
 }
 
 static inline int dev_pm_opp_set_supported_hw(struct device *dev,