Skip to content

Commit

Permalink
cpuidle: make cpuidle_curr_driver static
Browse files Browse the repository at this point in the history
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: Len Brown <len.brown@intel.com>
  • Loading branch information
Len Brown committed May 28, 2010
1 parent c0d64cb commit 752138d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
12 changes: 7 additions & 5 deletions drivers/cpuidle/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev)

if (dev->enabled)
return 0;
if (!cpuidle_curr_driver || !cpuidle_curr_governor)
if (!cpuidle_get_driver() || !cpuidle_curr_governor)
return -EIO;
if (!dev->state_count)
return -EINVAL;
Expand Down Expand Up @@ -207,7 +207,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
{
if (!dev->enabled)
return;
if (!cpuidle_curr_driver || !cpuidle_curr_governor)
if (!cpuidle_get_driver() || !cpuidle_curr_governor)
return;

dev->enabled = 0;
Expand Down Expand Up @@ -271,10 +271,11 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
{
int ret;
struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();

if (!sys_dev)
return -EINVAL;
if (!try_module_get(cpuidle_curr_driver->owner))
if (!try_module_get(cpuidle_driver->owner))
return -EINVAL;

init_completion(&dev->kobj_unregister);
Expand All @@ -284,7 +285,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
per_cpu(cpuidle_devices, dev->cpu) = dev;
list_add(&dev->device_list, &cpuidle_detected_devices);
if ((ret = cpuidle_add_sysfs(sys_dev))) {
module_put(cpuidle_curr_driver->owner);
module_put(cpuidle_driver->owner);
return ret;
}

Expand Down Expand Up @@ -325,6 +326,7 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device);
void cpuidle_unregister_device(struct cpuidle_device *dev)
{
struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();

if (dev->registered == 0)
return;
Expand All @@ -340,7 +342,7 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)

cpuidle_resume_and_unlock();

module_put(cpuidle_curr_driver->owner);
module_put(cpuidle_driver->owner);
}

EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
Expand Down
1 change: 0 additions & 1 deletion drivers/cpuidle/cpuidle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

/* For internal use only */
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_detected_devices;
extern struct mutex cpuidle_lock;
Expand Down
11 changes: 10 additions & 1 deletion drivers/cpuidle/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "cpuidle.h"

struct cpuidle_driver *cpuidle_curr_driver;
static struct cpuidle_driver *cpuidle_curr_driver;
DEFINE_SPINLOCK(cpuidle_driver_lock);

/**
Expand All @@ -39,6 +39,15 @@ int cpuidle_register_driver(struct cpuidle_driver *drv)

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
* @drv: the driver
Expand Down
5 changes: 3 additions & 2 deletions drivers/cpuidle/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ static ssize_t show_current_driver(struct sysdev_class *class,
char *buf)
{
ssize_t ret;
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();

spin_lock(&cpuidle_driver_lock);
if (cpuidle_curr_driver)
ret = sprintf(buf, "%s\n", cpuidle_curr_driver->name);
if (cpuidle_driver)
ret = sprintf(buf, "%s\n", cpuidle_driver->name);
else
ret = sprintf(buf, "none\n");
spin_unlock(&cpuidle_driver_lock);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/cpuidle.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct cpuidle_driver {
#ifdef CONFIG_CPU_IDLE

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 int cpuidle_register_device(struct cpuidle_device *dev);
extern void cpuidle_unregister_device(struct cpuidle_device *dev);
Expand All @@ -138,6 +139,7 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);

static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
{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 int cpuidle_register_device(struct cpuidle_device *dev)
{return -ENODEV; }
Expand Down

0 comments on commit 752138d

Please sign in to comment.