Commit c654d60e authored by Jan Beulich's avatar Jan Beulich Committed by Linus Torvalds

[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: default avatarJan Beulich <jbeulich@novell.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 58bf6a2d
...@@ -216,11 +216,9 @@ static ssize_t write_mem(struct file * file, const char __user * buf, ...@@ -216,11 +216,9 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
copied = copy_from_user(ptr, buf, sz); copied = copy_from_user(ptr, buf, sz);
if (copied) { if (copied) {
ssize_t ret; written += sz - copied;
if (written)
ret = written + (sz - copied); break;
if (ret)
return ret;
return -EFAULT; return -EFAULT;
} }
buf += sz; buf += sz;
...@@ -456,11 +454,9 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf, ...@@ -456,11 +454,9 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
copied = copy_from_user(ptr, buf, sz); copied = copy_from_user(ptr, buf, sz);
if (copied) { if (copied) {
ssize_t ret; written += sz - copied;
if (written)
ret = written + (sz - copied); break;
if (ret)
return ret;
return -EFAULT; return -EFAULT;
} }
buf += sz; buf += sz;
...@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * file, const char __user * buf, ...@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
if (len) { if (len) {
written = copy_from_user(kbuf, buf, len); written = copy_from_user(kbuf, buf, len);
if (written) { if (written) {
ssize_t ret; if (wrote + virtr)
break;
free_page((unsigned long)kbuf); free_page((unsigned long)kbuf);
ret = wrote + virtr + (len - written); return -EFAULT;
return ret ? ret : -EFAULT;
} }
} }
len = vwrite(kbuf, (char *)p, len); len = vwrite(kbuf, (char *)p, len);
...@@ -563,8 +558,11 @@ static ssize_t write_port(struct file * file, const char __user * buf, ...@@ -563,8 +558,11 @@ static ssize_t write_port(struct file * file, const char __user * buf,
return -EFAULT; return -EFAULT;
while (count-- > 0 && i < 65536) { while (count-- > 0 && i < 65536) {
char c; char c;
if (__get_user(c, tmp)) if (__get_user(c, tmp)) {
if (tmp > buf)
break;
return -EFAULT; return -EFAULT;
}
outb(c,i); outb(c,i);
i++; i++;
tmp++; tmp++;
......
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