Thread (8 messages) 8 messages, 2 authors, 2012-04-03

[PATCH 3/6] Input: uinput - return number of bytes copied on partial reads

STALE5298d

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2012-03-31 06:06:31
Subsystem: input (keyboard, mouse, joystick, touchscreen) drivers, the rest · Maintainers: Dmitry Torokhov, Linus Torvalds

If uinput_read() fails after copying several events to userspace
we need to return number of bytes successfully copied, not -EFAULT.

Signed-off-by: Dmitry Torokhov <redacted>
---
 drivers/input/misc/uinput.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 5339c1d..a33a7b3 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -455,7 +455,8 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
 static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
 {
 	struct uinput_device *udev = file->private_data;
-	int retval = 0;
+	size_t read = 0;
+	int retval;
 
 	if (count < input_event_size())
 		return -EINVAL;
@@ -478,23 +479,23 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
 	}
 
 	while (udev->head != udev->tail &&
-               retval + input_event_size() <= count) {
-		if (input_event_to_user(buffer + retval,
+               read + input_event_size() <= count) {
+		if (input_event_to_user(buffer + read,
 					&udev->buff[udev->tail])) {
 			retval = -EFAULT;
 			goto out;
 		}
 		udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;
-		retval += input_event_size();
+		read += input_event_size();
 	}
 
-	if (retval == 0 && (file->f_flags & O_NONBLOCK))
+	if (read == 0 && (file->f_flags & O_NONBLOCK))
 		retval = -EAGAIN;
 
  out:
 	mutex_unlock(&udev->mutex);
 
-	return retval;
+	return read ?: retval;
 }
 
 static unsigned int uinput_poll(struct file *file, poll_table *wait)
-- 
1.7.7.6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help