From c654d60e8f0ea13e35b15cff54c0e473b8b162be Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Sat, 25 Mar 2006 03:07:31 -0800 Subject: [PATCH] adjust /dev/{kmem,mem,port} write handlers The /dev/mem and /dev/kmem write handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status. The /dev/port write handler was inconsistent with the /dev/mem and /dev/kmem handlers in that when encountering a -EFAULT condition after already having written a number of items it would return -EFAULT rather than the number of bytes written. Signed-off-by: Jan Beulich Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/mem.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 29c41f4418c..26d0116b48d 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -216,11 +216,9 @@ static ssize_t write_mem(struct file * file, const char __user * buf, copied = copy_from_user(ptr, buf, sz); if (copied) { - ssize_t ret; - - ret = written + (sz - copied); - if (ret) - return ret; + written += sz - copied; + if (written) + break; return -EFAULT; } buf += sz; @@ -456,11 +454,9 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf, copied = copy_from_user(ptr, buf, sz); if (copied) { - ssize_t ret; - - ret = written + (sz - copied); - if (ret) - return ret; + written += sz - copied; + if (written) + break; return -EFAULT; } buf += sz; @@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * file, const char __user * buf, if (len) { written = copy_from_user(kbuf, buf, len); if (written) { - ssize_t ret; - + if (wrote + virtr) + break; free_page((unsigned long)kbuf); - ret = wrote + virtr + (len - written); - return ret ? ret : -EFAULT; + return -EFAULT; } } len = vwrite(kbuf, (char *)p, len); @@ -563,8 +558,11 @@ static ssize_t write_port(struct file * file, const char __user * buf, return -EFAULT; while (count-- > 0 && i < 65536) { char c; - if (__get_user(c, tmp)) + if (__get_user(c, tmp)) { + if (tmp > buf) + break; return -EFAULT; + } outb(c,i); i++; tmp++; -- cgit v1.2.3