If we encounter an error in middle of transferring several events from userspace we should return number of bytes successfully transferred instead of error code. If transfer fails on the very first event then we can return error code. Signed-off-by: Dmitry Torokhov <dtor@xxxxxxx> --- drivers/input/evdev.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 9226b4d..0e32b6a 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -343,34 +343,35 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer, struct evdev_client *client = file->private_data; struct evdev *evdev = client->evdev; struct input_event event; - int retval = 0; + int written = 0; + int error; if (count < input_event_size()) return -EINVAL; - retval = mutex_lock_interruptible(&evdev->mutex); - if (retval) - return retval; + error = mutex_lock_interruptible(&evdev->mutex); + if (error) + return error; if (!evdev->exist) { - retval = -ENODEV; + error = -ENODEV; goto out; } do { - if (input_event_from_user(buffer + retval, &event)) { - retval = -EFAULT; + if (input_event_from_user(buffer + written, &event)) { + error = -EFAULT; goto out; } - retval += input_event_size(); + written += input_event_size(); input_inject_event(&evdev->handle, event.type, event.code, event.value); - } while (retval + input_event_size() <= count); + } while (written + input_event_size() <= count); out: mutex_unlock(&evdev->mutex); - return retval; + return written ?: error; } static int evdev_fetch_next_event(struct evdev_client *client, -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html