diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2012-06-16 15:20:11 +0200 |
---|---|---|
committer | Simone Willett <swillett@nvidia.com> | 2012-10-19 12:19:42 -0700 |
commit | c950d1da8ff609f071a9cfbb56e469491d034c22 (patch) | |
tree | b0517b88634d92ee5f8e5298d7f6a5e476c05f6f /drivers/cpuidle/driver.c | |
parent | c0c9d77cf33769e5874d6d98beb9378a247b86e4 (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>
(cherry picked from commit 6e797a078824b30afbfae6cc4b1c2b21c51761ef)
Change-Id: I41efc4cd5f99cbcfd1431ca2ac47e9aac1a11127
Signed-off-by: Prashant Gaikwad <pgaikwad@nvidia.com>
Reviewed-on: http://git-master/r/145221
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
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 3f7e3cedd133..15216dad0bfc 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -16,6 +16,7 @@ static struct cpuidle_driver *cpuidle_curr_driver; DEFINE_SPINLOCK(cpuidle_driver_lock); +int cpuidle_driver_refcount; /** * cpuidle_register_driver - registers a driver @@ -64,8 +65,34 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv) } spin_lock(&cpuidle_driver_lock); - cpuidle_curr_driver = NULL; + + if (!WARN_ON(cpuidle_driver_refcount > 0)) + cpuidle_curr_driver = NULL; + spin_unlock(&cpuidle_driver_lock); } EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); + +struct cpuidle_driver *cpuidle_driver_ref(void) +{ + struct cpuidle_driver *drv; + + spin_lock(&cpuidle_driver_lock); + + drv = cpuidle_curr_driver; + cpuidle_driver_refcount++; + + spin_unlock(&cpuidle_driver_lock); + return drv; +} + +void cpuidle_driver_unref(void) +{ + spin_lock(&cpuidle_driver_lock); + + if (!WARN_ON(cpuidle_driver_refcount <= 0)) + cpuidle_driver_refcount--; + + spin_unlock(&cpuidle_driver_lock); +} |