diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2012-06-16 09:20:11 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2012-07-03 13:06:25 -0400 |
commit | 6e797a078824b30afbfae6cc4b1c2b21c51761ef (patch) | |
tree | 7f58824b2c1e62b954683900024a5b97a4d30b4d /drivers/cpuidle/driver.c | |
parent | dc7fd275ae60ef8edf952aff2a62462f5d892fd4 (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/driver.c')
-rw-r--r-- | drivers/cpuidle/driver.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 40cd3f3024df..58bf3b1ac9c4 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | static struct cpuidle_driver *cpuidle_curr_driver; | 17 | static struct cpuidle_driver *cpuidle_curr_driver; |
18 | DEFINE_SPINLOCK(cpuidle_driver_lock); | 18 | DEFINE_SPINLOCK(cpuidle_driver_lock); |
19 | int cpuidle_driver_refcount; | ||
19 | 20 | ||
20 | static void __cpuidle_register_driver(struct cpuidle_driver *drv) | 21 | static 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 | ||
96 | EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); | 100 | EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); |
101 | |||
102 | struct 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 | |||
115 | void 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 | } | ||