Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1549056
| Path | csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Viresh Kumar <viresh.kumar@linaro.org> |
| Newsgroups | linux.kernel |
| Subject | [PATCH V3 09/10] PM / OPP: Don't expose srcu_head to register notifiers |
| Date | Mon, 02 Jan 2017 10:20:02 +0100 |
| Message-ID | <sV6WC-4G8-29@gated-at.bofh.it> (permalink) |
| References | <sV6WB-4G8-11@gated-at.bofh.it> |
| X-Original-To | Rafael Wysocki <rjw@rjwysocki.net>, Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>, Stephen Boyd <sboyd@codeaurora.org>, MyungJoo Ham <myungjoo.ham@samsung.com>, Kyungmin Park <kyungmin.park@samsung.com> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4b1pxSz6dHv4U6BkJHmyt/7x7JIV11IcRZoSczOj2l0=; b=dQ9t6v8buAFOnAbDfaxzFZW9LcCngJqt8F97jTg01yH2PHEfvP6jmu3CJ840UI9JM1 9Pw2lMT77CbdSMnCthS10wBL5k4Y4iwA8u8Tg+CcMJzXFKvM8u3XMdsXgK3NHDhkSQGh ELHM7SgxD8RzaNWcnwvvZnOyxrK9X2Fe5cxMo= |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=4b1pxSz6dHv4U6BkJHmyt/7x7JIV11IcRZoSczOj2l0=; b=pw29ckzg9FP6v6kK31CHjWk05CoCcq+GOQJUkaokYYc/HVi8vA79LbK/rFdDNUFa+/ O8zzd0b8g+xtqAO4Ibl9dRAR161KB54ZOImQzmn5gs1MN3SmVrgqZixxc1NQ88qUA/b3 O4DrIseFcR89OhL3j3af6Dc2gA0m76Qet+edssh2f2sImY7U7wecqU+PK2Chs0mFUDHB ZZgNyo4+xPej3ss/SnMTteY0udtM/MAChLC6hwlGhxH88ZZTGFklNBeSeRbdavyLfnk6 1KrmYYPQ/rggWjmLicxAgmyJd3ALgpq3o9pjjUjtua9JrdpCLXxY0TRtiX0Hk+Kz+lz3 iKjQ== |
| X-Gm-Message-State | AIkVDXJf3HVNHUUtUUgsWoP5XJDc4a/Z6osk81+LGDBOI2I6N32aqOksZkE5dPMppuaVXCSP |
| X-Received | by 10.99.129.67 with SMTP id t64mr104352645pgd.4.1483348303494; Mon, 02 Jan 2017 01:11:43 -0800 (PST) |
| X-Mailer | git-send-email 2.7.1.410.g6faf27b |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 175 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot <vincent.guittot@linaro.org>, Viresh Kumar <viresh.kumar@linaro.org> |
| X-Original-Date | Mon, 2 Jan 2017 14:41:03 +0530 |
| X-Original-Message-ID | <9fd836f5bc197a04c9879054a8dd469028679d8b.1483348138.git.viresh.kumar@linaro.org> |
| X-Original-References | <cover.1483348138.git.viresh.kumar@linaro.org> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1549056 |
Show key headers only | View raw
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>
---
drivers/base/power/opp/core.c | 66 ++++++++++++++++++++++++++++++++-----------
drivers/devfreq/devfreq.c | 26 ++---------------
include/linux/pm_opp.h | 14 ++++++---
3 files changed, 62 insertions(+), 44 deletions(-)
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 614d779ab6a2..f35effad60d1 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -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
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index a324801d6a66..b0de42972b74 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1260,18 +1260,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);
@@ -1287,18 +1276,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);
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 7483ff291a8e..66a02deeb03f 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -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,
--
2.7.1.410.g6faf27b
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH V3 00/10] PM / OPP: Fixes and cleanups Viresh Kumar <viresh.kumar@linaro.org> - 2017-01-02 10:20 +0100 [PATCH V3 09/10] PM / OPP: Don't expose srcu_head to register notifiers Viresh Kumar <viresh.kumar@linaro.org> - 2017-01-02 10:20 +0100 [PATCH V3 01/10] PM / OPP: Fix memory leak while adding duplicate OPPs Viresh Kumar <viresh.kumar@linaro.org> - 2017-01-02 10:20 +0100 [PATCH V3 06/10] PM / OPP: Rename and split _dev_pm_opp_remove_table() Viresh Kumar <viresh.kumar@linaro.org> - 2017-01-02 10:20 +0100
csiph-web