Commit 85f1cb60 authored by H. Peter Anvin's avatar H. Peter Anvin

x86: msr: correct return value on partial operations

Return the correct return value when the MSR driver partially
completes a request (we should return the number of bytes actually
read or written, instead of the error code.)
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
parent 4b46ca70
...@@ -72,7 +72,8 @@ static ssize_t msr_read(struct file *file, char __user *buf, ...@@ -72,7 +72,8 @@ static ssize_t msr_read(struct file *file, char __user *buf,
u32 data[2]; u32 data[2];
u32 reg = *ppos; u32 reg = *ppos;
int cpu = iminor(file->f_path.dentry->d_inode); int cpu = iminor(file->f_path.dentry->d_inode);
int err; int err = 0;
ssize_t bytes = 0;
if (count % 8) if (count % 8)
return -EINVAL; /* Invalid chunk size */ return -EINVAL; /* Invalid chunk size */
...@@ -82,14 +83,17 @@ static ssize_t msr_read(struct file *file, char __user *buf, ...@@ -82,14 +83,17 @@ static ssize_t msr_read(struct file *file, char __user *buf,
if (err) { if (err) {
if (err == -EFAULT) /* Fix idiotic error code */ if (err == -EFAULT) /* Fix idiotic error code */
err = -EIO; err = -EIO;
return err; break;
}
if (copy_to_user(tmp, &data, 8)) {
err = -EFAULT;
break;
} }
if (copy_to_user(tmp, &data, 8))
return -EFAULT;
tmp += 2; tmp += 2;
bytes += 8;
} }
return ((char __user *)tmp) - buf; return bytes ? bytes : err;
} }
static ssize_t msr_write(struct file *file, const char __user *buf, static ssize_t msr_write(struct file *file, const char __user *buf,
...@@ -99,24 +103,28 @@ static ssize_t msr_write(struct file *file, const char __user *buf, ...@@ -99,24 +103,28 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
u32 data[2]; u32 data[2];
u32 reg = *ppos; u32 reg = *ppos;
int cpu = iminor(file->f_path.dentry->d_inode); int cpu = iminor(file->f_path.dentry->d_inode);
int err; int err = 0;
ssize_t bytes = 0;
if (count % 8) if (count % 8)
return -EINVAL; /* Invalid chunk size */ return -EINVAL; /* Invalid chunk size */
for (; count; count -= 8) { for (; count; count -= 8) {
if (copy_from_user(&data, tmp, 8)) if (copy_from_user(&data, tmp, 8)) {
return -EFAULT; err = -EFAULT;
break;
}
err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]); err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]);
if (err) { if (err) {
if (err == -EFAULT) /* Fix idiotic error code */ if (err == -EFAULT) /* Fix idiotic error code */
err = -EIO; err = -EIO;
return err; break;
} }
tmp += 2; tmp += 2;
bytes += 8;
} }
return ((char __user *)tmp) - buf; return bytes ? bytes : err;
} }
static int msr_open(struct inode *inode, struct file *file) static int msr_open(struct inode *inode, struct file *file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment