aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/cpuid.c')
-rw-r--r--arch/x86/kernel/cpuid.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index daff52a62248..6a44d6465991 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -33,9 +33,9 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/poll.h> 34#include <linux/poll.h>
35#include <linux/smp.h> 35#include <linux/smp.h>
36#include <linux/smp_lock.h>
36#include <linux/major.h> 37#include <linux/major.h>
37#include <linux/fs.h> 38#include <linux/fs.h>
38#include <linux/smp_lock.h>
39#include <linux/device.h> 39#include <linux/device.h>
40#include <linux/cpu.h> 40#include <linux/cpu.h>
41#include <linux/notifier.h> 41#include <linux/notifier.h>
@@ -88,6 +88,8 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
88 struct cpuid_regs cmd; 88 struct cpuid_regs cmd;
89 int cpu = iminor(file->f_path.dentry->d_inode); 89 int cpu = iminor(file->f_path.dentry->d_inode);
90 u64 pos = *ppos; 90 u64 pos = *ppos;
91 ssize_t bytes = 0;
92 int err = 0;
91 93
92 if (count % 16) 94 if (count % 16)
93 return -EINVAL; /* Invalid chunk size */ 95 return -EINVAL; /* Invalid chunk size */
@@ -95,27 +97,40 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
95 for (; count; count -= 16) { 97 for (; count; count -= 16) {
96 cmd.eax = pos; 98 cmd.eax = pos;
97 cmd.ecx = pos >> 32; 99 cmd.ecx = pos >> 32;
98 smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1, 1); 100 err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1);
99 if (copy_to_user(tmp, &cmd, 16)) 101 if (err)
100 return -EFAULT; 102 break;
103 if (copy_to_user(tmp, &cmd, 16)) {
104 err = -EFAULT;
105 break;
106 }
101 tmp += 16; 107 tmp += 16;
108 bytes += 16;
102 *ppos = ++pos; 109 *ppos = ++pos;
103 } 110 }
104 111
105 return tmp - buf; 112 return bytes ? bytes : err;
106} 113}
107 114
108static int cpuid_open(struct inode *inode, struct file *file) 115static int cpuid_open(struct inode *inode, struct file *file)
109{ 116{
110 unsigned int cpu = iminor(file->f_path.dentry->d_inode); 117 unsigned int cpu;
111 struct cpuinfo_x86 *c = &cpu_data(cpu); 118 struct cpuinfo_x86 *c;
112 119 int ret = 0;
113 if (cpu >= NR_CPUS || !cpu_online(cpu)) 120
114 return -ENXIO; /* No such CPU */ 121 lock_kernel();
122
123 cpu = iminor(file->f_path.dentry->d_inode);
124 if (cpu >= NR_CPUS || !cpu_online(cpu)) {
125 ret = -ENXIO; /* No such CPU */
126 goto out;
127 }
128 c = &cpu_data(cpu);
115 if (c->cpuid_level < 0) 129 if (c->cpuid_level < 0)
116 return -EIO; /* CPUID not supported */ 130 ret = -EIO; /* CPUID not supported */
117 131out:
118 return 0; 132 unlock_kernel();
133 return ret;
119} 134}
120 135
121/* 136/*
@@ -132,8 +147,8 @@ static __cpuinit int cpuid_device_create(int cpu)
132{ 147{
133 struct device *dev; 148 struct device *dev;
134 149
135 dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), 150 dev = device_create_drvdata(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu),
136 "cpu%d", cpu); 151 NULL, "cpu%d", cpu);
137 return IS_ERR(dev) ? PTR_ERR(dev) : 0; 152 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
138} 153}
139 154