Commit 752138df authored by Len Brown's avatar Len Brown

cpuidle: make cpuidle_curr_driver static

cpuidle_register_driver() sets cpuidle_curr_driver
cpuidle_unregister_driver() clears cpuidle_curr_driver

We should't expose cpuidle_curr_driver to
potential modification except via these interfaces.
So make it static and create cpuidle_get_driver() to observe it.
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent c0d64cb0
...@@ -156,7 +156,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev) ...@@ -156,7 +156,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
if (dev->enabled) if (dev->enabled)
return 0; return 0;
if (!cpuidle_curr_driver || !cpuidle_curr_governor) if (!cpuidle_get_driver() || !cpuidle_curr_governor)
return -EIO; return -EIO;
if (!dev->state_count) if (!dev->state_count)
return -EINVAL; return -EINVAL;
...@@ -207,7 +207,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev) ...@@ -207,7 +207,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
{ {
if (!dev->enabled) if (!dev->enabled)
return; return;
if (!cpuidle_curr_driver || !cpuidle_curr_governor) if (!cpuidle_get_driver() || !cpuidle_curr_governor)
return; return;
dev->enabled = 0; dev->enabled = 0;
...@@ -271,10 +271,11 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) ...@@ -271,10 +271,11 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
{ {
int ret; int ret;
struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
if (!sys_dev) if (!sys_dev)
return -EINVAL; return -EINVAL;
if (!try_module_get(cpuidle_curr_driver->owner)) if (!try_module_get(cpuidle_driver->owner))
return -EINVAL; return -EINVAL;
init_completion(&dev->kobj_unregister); init_completion(&dev->kobj_unregister);
...@@ -284,7 +285,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) ...@@ -284,7 +285,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
per_cpu(cpuidle_devices, dev->cpu) = dev; per_cpu(cpuidle_devices, dev->cpu) = dev;
list_add(&dev->device_list, &cpuidle_detected_devices); list_add(&dev->device_list, &cpuidle_detected_devices);
if ((ret = cpuidle_add_sysfs(sys_dev))) { if ((ret = cpuidle_add_sysfs(sys_dev))) {
module_put(cpuidle_curr_driver->owner); module_put(cpuidle_driver->owner);
return ret; return ret;
} }
...@@ -325,6 +326,7 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device); ...@@ -325,6 +326,7 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device);
void cpuidle_unregister_device(struct cpuidle_device *dev) void cpuidle_unregister_device(struct cpuidle_device *dev)
{ {
struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
if (dev->registered == 0) if (dev->registered == 0)
return; return;
...@@ -340,7 +342,7 @@ void cpuidle_unregister_device(struct cpuidle_device *dev) ...@@ -340,7 +342,7 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)
cpuidle_resume_and_unlock(); cpuidle_resume_and_unlock();
module_put(cpuidle_curr_driver->owner); module_put(cpuidle_driver->owner);
} }
EXPORT_SYMBOL_GPL(cpuidle_unregister_device); EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
/* For internal use only */ /* For internal use only */
extern struct cpuidle_governor *cpuidle_curr_governor; extern struct cpuidle_governor *cpuidle_curr_governor;
extern struct cpuidle_driver *cpuidle_curr_driver;
extern struct list_head cpuidle_governors; extern struct list_head cpuidle_governors;
extern struct list_head cpuidle_detected_devices; extern struct list_head cpuidle_detected_devices;
extern struct mutex cpuidle_lock; extern struct mutex cpuidle_lock;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "cpuidle.h" #include "cpuidle.h"
struct cpuidle_driver *cpuidle_curr_driver; static struct cpuidle_driver *cpuidle_curr_driver;
DEFINE_SPINLOCK(cpuidle_driver_lock); DEFINE_SPINLOCK(cpuidle_driver_lock);
/** /**
...@@ -39,6 +39,15 @@ int cpuidle_register_driver(struct cpuidle_driver *drv) ...@@ -39,6 +39,15 @@ int cpuidle_register_driver(struct cpuidle_driver *drv)
EXPORT_SYMBOL_GPL(cpuidle_register_driver); EXPORT_SYMBOL_GPL(cpuidle_register_driver);
/**
* cpuidle_get_driver - return the current driver
*/
struct cpuidle_driver *cpuidle_get_driver(void)
{
return cpuidle_curr_driver;
}
EXPORT_SYMBOL_GPL(cpuidle_get_driver);
/** /**
* cpuidle_unregister_driver - unregisters a driver * cpuidle_unregister_driver - unregisters a driver
* @drv: the driver * @drv: the driver
......
...@@ -47,10 +47,11 @@ static ssize_t show_current_driver(struct sysdev_class *class, ...@@ -47,10 +47,11 @@ static ssize_t show_current_driver(struct sysdev_class *class,
char *buf) char *buf)
{ {
ssize_t ret; ssize_t ret;
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
spin_lock(&cpuidle_driver_lock); spin_lock(&cpuidle_driver_lock);
if (cpuidle_curr_driver) if (cpuidle_driver)
ret = sprintf(buf, "%s\n", cpuidle_curr_driver->name); ret = sprintf(buf, "%s\n", cpuidle_driver->name);
else else
ret = sprintf(buf, "none\n"); ret = sprintf(buf, "none\n");
spin_unlock(&cpuidle_driver_lock); spin_unlock(&cpuidle_driver_lock);
......
...@@ -125,6 +125,7 @@ struct cpuidle_driver { ...@@ -125,6 +125,7 @@ struct cpuidle_driver {
#ifdef CONFIG_CPU_IDLE #ifdef CONFIG_CPU_IDLE
extern int cpuidle_register_driver(struct cpuidle_driver *drv); extern int cpuidle_register_driver(struct cpuidle_driver *drv);
struct cpuidle_driver *cpuidle_get_driver(void);
extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
extern int cpuidle_register_device(struct cpuidle_device *dev); extern int cpuidle_register_device(struct cpuidle_device *dev);
extern void cpuidle_unregister_device(struct cpuidle_device *dev); extern void cpuidle_unregister_device(struct cpuidle_device *dev);
...@@ -138,6 +139,7 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev); ...@@ -138,6 +139,7 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);
static inline int cpuidle_register_driver(struct cpuidle_driver *drv) static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
{return -ENODEV; } {return -ENODEV; }
static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { } static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
static inline int cpuidle_register_device(struct cpuidle_device *dev) static inline int cpuidle_register_device(struct cpuidle_device *dev)
{return -ENODEV; } {return -ENODEV; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment