x86: cpuid: correct return value on partial operations

Return the correct return value when the CPUID driver partially
completes a request (we should return the number of bytes actually
read or written, instead of the error code.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

+9 -5
+9 -5
arch/x86/kernel/cpuid.c
··· 89 struct cpuid_regs cmd; 90 int cpu = iminor(file->f_path.dentry->d_inode); 91 u64 pos = *ppos; 92 - int err; 93 94 if (count % 16) 95 return -EINVAL; /* Invalid chunk size */ ··· 100 cmd.ecx = pos >> 32; 101 err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1); 102 if (err) 103 - return err; 104 - if (copy_to_user(tmp, &cmd, 16)) 105 - return -EFAULT; 106 tmp += 16; 107 *ppos = ++pos; 108 } 109 110 - return tmp - buf; 111 } 112 113 static int cpuid_open(struct inode *inode, struct file *file)
··· 89 struct cpuid_regs cmd; 90 int cpu = iminor(file->f_path.dentry->d_inode); 91 u64 pos = *ppos; 92 + ssize_t bytes = 0; 93 + int err = 0; 94 95 if (count % 16) 96 return -EINVAL; /* Invalid chunk size */ ··· 99 cmd.ecx = pos >> 32; 100 err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1); 101 if (err) 102 + break; 103 + if (copy_to_user(tmp, &cmd, 16)) { 104 + err = -EFAULT; 105 + break; 106 + } 107 tmp += 16; 108 + bytes += 16; 109 *ppos = ++pos; 110 } 111 112 + return bytes ? bytes : err; 113 } 114 115 static int cpuid_open(struct inode *inode, struct file *file)