diff options
author | Jan Beulich <JBeulich@novell.com> | 2006-03-25 06:07:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-25 11:22:55 -0500 |
commit | c654d60e8f0ea13e35b15cff54c0e473b8b162be (patch) | |
tree | 5c496d488666225909ab1eb7e116827cd013ae60 /drivers | |
parent | 58bf6a2db2a4a1b41712674d9165510180259dec (diff) |
[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 <jbeulich@novell.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/mem.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 29c41f4418c0..26d0116b48d4 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, | |||
216 | 216 | ||
217 | copied = copy_from_user(ptr, buf, sz); | 217 | copied = copy_from_user(ptr, buf, sz); |
218 | if (copied) { | 218 | if (copied) { |
219 | ssize_t ret; | 219 | written += sz - copied; |
220 | 220 | if (written) | |
221 | ret = written + (sz - copied); | 221 | break; |
222 | if (ret) | ||
223 | return ret; | ||
224 | return -EFAULT; | 222 | return -EFAULT; |
225 | } | 223 | } |
226 | buf += sz; | 224 | buf += sz; |
@@ -456,11 +454,9 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf, | |||
456 | 454 | ||
457 | copied = copy_from_user(ptr, buf, sz); | 455 | copied = copy_from_user(ptr, buf, sz); |
458 | if (copied) { | 456 | if (copied) { |
459 | ssize_t ret; | 457 | written += sz - copied; |
460 | 458 | if (written) | |
461 | ret = written + (sz - copied); | 459 | break; |
462 | if (ret) | ||
463 | return ret; | ||
464 | return -EFAULT; | 460 | return -EFAULT; |
465 | } | 461 | } |
466 | buf += sz; | 462 | buf += sz; |
@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * file, const char __user * buf, | |||
514 | if (len) { | 510 | if (len) { |
515 | written = copy_from_user(kbuf, buf, len); | 511 | written = copy_from_user(kbuf, buf, len); |
516 | if (written) { | 512 | if (written) { |
517 | ssize_t ret; | 513 | if (wrote + virtr) |
518 | 514 | break; | |
519 | free_page((unsigned long)kbuf); | 515 | free_page((unsigned long)kbuf); |
520 | ret = wrote + virtr + (len - written); | 516 | return -EFAULT; |
521 | return ret ? ret : -EFAULT; | ||
522 | } | 517 | } |
523 | } | 518 | } |
524 | len = vwrite(kbuf, (char *)p, len); | 519 | len = vwrite(kbuf, (char *)p, len); |
@@ -563,8 +558,11 @@ static ssize_t write_port(struct file * file, const char __user * buf, | |||
563 | return -EFAULT; | 558 | return -EFAULT; |
564 | while (count-- > 0 && i < 65536) { | 559 | while (count-- > 0 && i < 65536) { |
565 | char c; | 560 | char c; |
566 | if (__get_user(c, tmp)) | 561 | if (__get_user(c, tmp)) { |
562 | if (tmp > buf) | ||
563 | break; | ||
567 | return -EFAULT; | 564 | return -EFAULT; |
565 | } | ||
568 | outb(c,i); | 566 | outb(c,i); |
569 | i++; | 567 | i++; |
570 | tmp++; | 568 | tmp++; |