1 From d330eae026b4a73e77ca0422f5cae5207d80f738 Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Mon, 1 Jun 2015 18:47:57 -0700
4 Subject: OPP: Allow notifiers to call dev_pm_opp_get_{voltage, freq} RCU-free
6 We pass the dev_pm_opp structure to OPP notifiers but the users
7 of the notifier need to surround calls to dev_pm_opp_get_*() with
8 RCU read locks to avoid lockdep warnings. The notifier is already
9 called with the dev_opp's srcu lock held, so it should be safe to
10 assume the devm_pm_opp structure is already protected inside the
11 notifier. Update the lockdep check for this.
13 Cc: Krzysztof Kozlowski <k.kozlowski@samsung.com>
14 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
16 drivers/base/power/opp/core.c | 27 +++++++++++++++------------
17 1 file changed, 15 insertions(+), 12 deletions(-)
19 --- a/drivers/base/power/opp/core.c
20 +++ b/drivers/base/power/opp/core.c
21 @@ -31,9 +31,10 @@ static LIST_HEAD(dev_opp_list);
22 /* Lock to allow exclusive modification to the device and opp lists */
23 DEFINE_MUTEX(dev_opp_list_lock);
25 -#define opp_rcu_lockdep_assert() \
26 +#define opp_rcu_lockdep_assert(s) \
28 RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
29 + !(s && srcu_read_lock_held(s)) && \
30 !lockdep_is_held(&dev_opp_list_lock), \
31 "Missing rcu_read_lock() or " \
32 "dev_opp_list_lock protection"); \
33 @@ -91,7 +92,7 @@ struct device_opp *_find_device_opp(stru
35 struct device_opp *dev_opp;
37 - opp_rcu_lockdep_assert();
38 + opp_rcu_lockdep_assert(NULL);
40 if (IS_ERR_OR_NULL(dev)) {
41 pr_err("%s: Invalid parameters\n", __func__);
42 @@ -125,10 +126,11 @@ unsigned long dev_pm_opp_get_voltage(str
43 struct dev_pm_opp *tmp_opp;
46 - opp_rcu_lockdep_assert();
47 + opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
49 - tmp_opp = rcu_dereference(opp);
50 - if (IS_ERR_OR_NULL(tmp_opp))
51 + tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
52 + rcu_read_lock_held());
53 + if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available)
54 pr_err("%s: Invalid parameters\n", __func__);
57 @@ -157,9 +159,10 @@ unsigned long dev_pm_opp_get_freq(struct
58 struct dev_pm_opp *tmp_opp;
61 - opp_rcu_lockdep_assert();
62 + opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
64 - tmp_opp = rcu_dereference(opp);
65 + tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
66 + rcu_read_lock_held());
67 if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available)
68 pr_err("%s: Invalid parameters\n", __func__);
70 @@ -191,7 +194,7 @@ bool dev_pm_opp_is_turbo(struct dev_pm_o
72 struct dev_pm_opp *tmp_opp;
74 - opp_rcu_lockdep_assert();
75 + opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
77 tmp_opp = rcu_dereference(opp);
78 if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available) {
79 @@ -246,7 +249,7 @@ struct dev_pm_opp *dev_pm_opp_get_suspen
81 struct device_opp *dev_opp;
83 - opp_rcu_lockdep_assert();
84 + opp_rcu_lockdep_assert(NULL);
86 dev_opp = _find_device_opp(dev);
87 if (IS_ERR(dev_opp) || !dev_opp->suspend_opp ||
88 @@ -326,7 +329,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_
89 struct device_opp *dev_opp;
90 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
92 - opp_rcu_lockdep_assert();
93 + opp_rcu_lockdep_assert(NULL);
95 dev_opp = _find_device_opp(dev);
96 if (IS_ERR(dev_opp)) {
97 @@ -374,7 +377,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_
98 struct device_opp *dev_opp;
99 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
101 - opp_rcu_lockdep_assert();
102 + opp_rcu_lockdep_assert(NULL);
105 dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
106 @@ -424,7 +427,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_
107 struct device_opp *dev_opp;
108 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
110 - opp_rcu_lockdep_assert();
111 + opp_rcu_lockdep_assert(NULL);
114 dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);