aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/msr.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/msr.c')
-rw-r--r--arch/x86/kernel/msr.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index 6a3cefc7dda1..4d4468e9f47c 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -37,6 +37,7 @@
37#include <linux/cpu.h> 37#include <linux/cpu.h>
38#include <linux/notifier.h> 38#include <linux/notifier.h>
39#include <linux/uaccess.h> 39#include <linux/uaccess.h>
40#include <linux/gfp.h>
40 41
41#include <asm/processor.h> 42#include <asm/processor.h>
42#include <asm/msr.h> 43#include <asm/msr.h>
@@ -172,23 +173,18 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
172 173
173static int msr_open(struct inode *inode, struct file *file) 174static int msr_open(struct inode *inode, struct file *file)
174{ 175{
175 unsigned int cpu = iminor(file->f_path.dentry->d_inode); 176 unsigned int cpu;
176 struct cpuinfo_x86 *c = &cpu_data(cpu); 177 struct cpuinfo_x86 *c;
177 int ret = 0;
178 178
179 lock_kernel();
180 cpu = iminor(file->f_path.dentry->d_inode); 179 cpu = iminor(file->f_path.dentry->d_inode);
180 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
181 return -ENXIO; /* No such CPU */
181 182
182 if (cpu >= nr_cpu_ids || !cpu_online(cpu)) {
183 ret = -ENXIO; /* No such CPU */
184 goto out;
185 }
186 c = &cpu_data(cpu); 183 c = &cpu_data(cpu);
187 if (!cpu_has(c, X86_FEATURE_MSR)) 184 if (!cpu_has(c, X86_FEATURE_MSR))
188 ret = -EIO; /* MSR not supported */ 185 return -EIO; /* MSR not supported */
189out: 186
190 unlock_kernel(); 187 return 0;
191 return ret;
192} 188}
193 189
194/* 190/*
@@ -251,7 +247,7 @@ static int __init msr_init(void)
251 int i, err = 0; 247 int i, err = 0;
252 i = 0; 248 i = 0;
253 249
254 if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) { 250 if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) {
255 printk(KERN_ERR "msr: unable to get major %d for msr\n", 251 printk(KERN_ERR "msr: unable to get major %d for msr\n",
256 MSR_MAJOR); 252 MSR_MAJOR);
257 err = -EBUSY; 253 err = -EBUSY;
@@ -279,7 +275,7 @@ out_class:
279 msr_device_destroy(i); 275 msr_device_destroy(i);
280 class_destroy(msr_class); 276 class_destroy(msr_class);
281out_chrdev: 277out_chrdev:
282 unregister_chrdev(MSR_MAJOR, "cpu/msr"); 278 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
283out: 279out:
284 return err; 280 return err;
285} 281}
@@ -290,7 +286,7 @@ static void __exit msr_exit(void)
290 for_each_online_cpu(cpu) 286 for_each_online_cpu(cpu)
291 msr_device_destroy(cpu); 287 msr_device_destroy(cpu);
292 class_destroy(msr_class); 288 class_destroy(msr_class);
293 unregister_chrdev(MSR_MAJOR, "cpu/msr"); 289 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
294 unregister_hotcpu_notifier(&msr_class_cpu_notifier); 290 unregister_hotcpu_notifier(&msr_class_cpu_notifier);
295} 291}
296 292