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: Len Brown <len.brown@intel.com>

Len Brown 752138df c0d64cb0

+22 -9
+7 -5
drivers/cpuidle/cpuidle.c
··· 156 157 if (dev->enabled) 158 return 0; 159 - if (!cpuidle_curr_driver || !cpuidle_curr_governor) 160 return -EIO; 161 if (!dev->state_count) 162 return -EINVAL; ··· 207 { 208 if (!dev->enabled) 209 return; 210 - if (!cpuidle_curr_driver || !cpuidle_curr_governor) 211 return; 212 213 dev->enabled = 0; ··· 271 { 272 int ret; 273 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); 274 275 if (!sys_dev) 276 return -EINVAL; 277 - if (!try_module_get(cpuidle_curr_driver->owner)) 278 return -EINVAL; 279 280 init_completion(&dev->kobj_unregister); ··· 285 per_cpu(cpuidle_devices, dev->cpu) = dev; 286 list_add(&dev->device_list, &cpuidle_detected_devices); 287 if ((ret = cpuidle_add_sysfs(sys_dev))) { 288 - module_put(cpuidle_curr_driver->owner); 289 return ret; 290 } 291 ··· 326 void cpuidle_unregister_device(struct cpuidle_device *dev) 327 { 328 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); 329 330 if (dev->registered == 0) 331 return; ··· 342 343 cpuidle_resume_and_unlock(); 344 345 - module_put(cpuidle_curr_driver->owner); 346 } 347 348 EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
··· 156 157 if (dev->enabled) 158 return 0; 159 + if (!cpuidle_get_driver() || !cpuidle_curr_governor) 160 return -EIO; 161 if (!dev->state_count) 162 return -EINVAL; ··· 207 { 208 if (!dev->enabled) 209 return; 210 + if (!cpuidle_get_driver() || !cpuidle_curr_governor) 211 return; 212 213 dev->enabled = 0; ··· 271 { 272 int ret; 273 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); 274 + struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver(); 275 276 if (!sys_dev) 277 return -EINVAL; 278 + if (!try_module_get(cpuidle_driver->owner)) 279 return -EINVAL; 280 281 init_completion(&dev->kobj_unregister); ··· 284 per_cpu(cpuidle_devices, dev->cpu) = dev; 285 list_add(&dev->device_list, &cpuidle_detected_devices); 286 if ((ret = cpuidle_add_sysfs(sys_dev))) { 287 + module_put(cpuidle_driver->owner); 288 return ret; 289 } 290 ··· 325 void cpuidle_unregister_device(struct cpuidle_device *dev) 326 { 327 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu); 328 + struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver(); 329 330 if (dev->registered == 0) 331 return; ··· 340 341 cpuidle_resume_and_unlock(); 342 343 + module_put(cpuidle_driver->owner); 344 } 345 346 EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
-1
drivers/cpuidle/cpuidle.h
··· 9 10 /* For internal use only */ 11 extern struct cpuidle_governor *cpuidle_curr_governor; 12 - extern struct cpuidle_driver *cpuidle_curr_driver; 13 extern struct list_head cpuidle_governors; 14 extern struct list_head cpuidle_detected_devices; 15 extern struct mutex cpuidle_lock;
··· 9 10 /* For internal use only */ 11 extern struct cpuidle_governor *cpuidle_curr_governor; 12 extern struct list_head cpuidle_governors; 13 extern struct list_head cpuidle_detected_devices; 14 extern struct mutex cpuidle_lock;
+10 -1
drivers/cpuidle/driver.c
··· 14 15 #include "cpuidle.h" 16 17 - struct cpuidle_driver *cpuidle_curr_driver; 18 DEFINE_SPINLOCK(cpuidle_driver_lock); 19 20 /** ··· 38 } 39 40 EXPORT_SYMBOL_GPL(cpuidle_register_driver); 41 42 /** 43 * cpuidle_unregister_driver - unregisters a driver
··· 14 15 #include "cpuidle.h" 16 17 + static struct cpuidle_driver *cpuidle_curr_driver; 18 DEFINE_SPINLOCK(cpuidle_driver_lock); 19 20 /** ··· 38 } 39 40 EXPORT_SYMBOL_GPL(cpuidle_register_driver); 41 + 42 + /** 43 + * cpuidle_get_driver - return the current driver 44 + */ 45 + struct cpuidle_driver *cpuidle_get_driver(void) 46 + { 47 + return cpuidle_curr_driver; 48 + } 49 + EXPORT_SYMBOL_GPL(cpuidle_get_driver); 50 51 /** 52 * cpuidle_unregister_driver - unregisters a driver
+3 -2
drivers/cpuidle/sysfs.c
··· 47 char *buf) 48 { 49 ssize_t ret; 50 51 spin_lock(&cpuidle_driver_lock); 52 - if (cpuidle_curr_driver) 53 - ret = sprintf(buf, "%s\n", cpuidle_curr_driver->name); 54 else 55 ret = sprintf(buf, "none\n"); 56 spin_unlock(&cpuidle_driver_lock);
··· 47 char *buf) 48 { 49 ssize_t ret; 50 + struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver(); 51 52 spin_lock(&cpuidle_driver_lock); 53 + if (cpuidle_driver) 54 + ret = sprintf(buf, "%s\n", cpuidle_driver->name); 55 else 56 ret = sprintf(buf, "none\n"); 57 spin_unlock(&cpuidle_driver_lock);
+2
include/linux/cpuidle.h
··· 125 #ifdef CONFIG_CPU_IDLE 126 127 extern int cpuidle_register_driver(struct cpuidle_driver *drv); 128 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); 129 extern int cpuidle_register_device(struct cpuidle_device *dev); 130 extern void cpuidle_unregister_device(struct cpuidle_device *dev); ··· 139 140 static inline int cpuidle_register_driver(struct cpuidle_driver *drv) 141 {return -ENODEV; } 142 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { } 143 static inline int cpuidle_register_device(struct cpuidle_device *dev) 144 {return -ENODEV; }
··· 125 #ifdef CONFIG_CPU_IDLE 126 127 extern int cpuidle_register_driver(struct cpuidle_driver *drv); 128 + struct cpuidle_driver *cpuidle_get_driver(void); 129 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); 130 extern int cpuidle_register_device(struct cpuidle_device *dev); 131 extern void cpuidle_unregister_device(struct cpuidle_device *dev); ··· 138 139 static inline int cpuidle_register_driver(struct cpuidle_driver *drv) 140 {return -ENODEV; } 141 + static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; } 142 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { } 143 static inline int cpuidle_register_device(struct cpuidle_device *dev) 144 {return -ENODEV; }