Commit 7a0a27d2 authored by Che-Liang Chiou's avatar Che-Liang Chiou Committed by Dmitry Torokhov

Input: serio_raw - return proper result when serio_raw_read fails

serio_raw_read now returns (sometimes partially) successful number of
bytes transferred to the caller, and only returns error code to the
caller on completely failed transfers.
Signed-off-by: default avatarChe-Liang Chiou <clchiou@chromium.org>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent d04df023
...@@ -164,7 +164,8 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer, ...@@ -164,7 +164,8 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer,
struct serio_raw_client *client = file->private_data; struct serio_raw_client *client = file->private_data;
struct serio_raw *serio_raw = client->serio_raw; struct serio_raw *serio_raw = client->serio_raw;
char uninitialized_var(c); char uninitialized_var(c);
ssize_t retval = 0; ssize_t read = 0;
int retval;
if (serio_raw->dead) if (serio_raw->dead)
return -ENODEV; return -ENODEV;
...@@ -180,13 +181,15 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer, ...@@ -180,13 +181,15 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer,
if (serio_raw->dead) if (serio_raw->dead)
return -ENODEV; return -ENODEV;
while (retval < count && serio_raw_fetch_byte(serio_raw, &c)) { while (read < count && serio_raw_fetch_byte(serio_raw, &c)) {
if (put_user(c, buffer++)) if (put_user(c, buffer++)) {
return -EFAULT; retval = -EFAULT;
retval++; break;
}
read++;
} }
return retval; return read ?: retval;
} }
static ssize_t serio_raw_write(struct file *file, const char __user *buffer, static ssize_t serio_raw_write(struct file *file, const char __user *buffer,
......
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