aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2012-06-16 09:20:11 -0400
committerRafael J. Wysocki <rjw@sisk.pl>2012-07-03 13:06:25 -0400
commit6e797a078824b30afbfae6cc4b1c2b21c51761ef (patch)
tree7f58824b2c1e62b954683900024a5b97a4d30b4d /drivers/cpuidle
parentdc7fd275ae60ef8edf952aff2a62462f5d892fd4 (diff)
PM / cpuidle: Add driver reference counter
Add a reference counter for the cpuidle driver, so that it can't be unregistered when it is in use. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'drivers/cpuidle')
-rw-r--r--drivers/cpuidle/driver.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 40cd3f3024d..58bf3b1ac9c 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -16,6 +16,7 @@
16 16
17static struct cpuidle_driver *cpuidle_curr_driver; 17static struct cpuidle_driver *cpuidle_curr_driver;
18DEFINE_SPINLOCK(cpuidle_driver_lock); 18DEFINE_SPINLOCK(cpuidle_driver_lock);
19int cpuidle_driver_refcount;
19 20
20static void __cpuidle_register_driver(struct cpuidle_driver *drv) 21static void __cpuidle_register_driver(struct cpuidle_driver *drv)
21{ 22{
@@ -89,8 +90,34 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv)
89 } 90 }
90 91
91 spin_lock(&cpuidle_driver_lock); 92 spin_lock(&cpuidle_driver_lock);
92 cpuidle_curr_driver = NULL; 93
94 if (!WARN_ON(cpuidle_driver_refcount > 0))
95 cpuidle_curr_driver = NULL;
96
93 spin_unlock(&cpuidle_driver_lock); 97 spin_unlock(&cpuidle_driver_lock);
94} 98}
95 99
96EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); 100EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
101
102struct cpuidle_driver *cpuidle_driver_ref(void)
103{
104 struct cpuidle_driver *drv;
105
106 spin_lock(&cpuidle_driver_lock);
107
108 drv = cpuidle_curr_driver;
109 cpuidle_driver_refcount++;
110
111 spin_unlock(&cpuidle_driver_lock);
112 return drv;
113}
114
115void cpuidle_driver_unref(void)
116{
117 spin_lock(&cpuidle_driver_lock);
118
119 if (!WARN_ON(cpuidle_driver_refcount <= 0))
120 cpuidle_driver_refcount--;
121
122 spin_unlock(&cpuidle_driver_lock);
123}