libfs: make simple_read_from_buffer conventional
PATCH 4/5 libfs: make simple_read_from_buffer conventional
From: Steven Rostedt <[email protected]>
Impact: have simple_read_from_buffer conform to standards
It was brought to my attention by Andrew Morton, Theodore Tso, and H. Peter Anvin that a read from userspace should only return -EFAULT if nothing was actually read.
Looking at the simple_read_from_buffer I noticed that this function does not conform to that rule. This patch fixes that function.
[[email protected]: simplification suggested by hpa]
[[email protected]: fix count==0 handling]
Signed-off-by Steven Rostedt <[email protected]>
Cc Al Viro <[email protected]>
Cc Theodore Ts'o <[email protected]>
Cc Ingo Molnar <[email protected]>
Signed-off-by H. Peter Anvin <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
fs/libfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/libfs.c renamed from fs/libfs.c~libfs-make-simple_read_from_buffer-conventional +6 -2
@@ -525,14 +525,18 @@ ssize_t simple_read_from_buffer(void __u const void *from, size_t available) {loff_t pos = *ppos; +size_t ret; +if (pos <0 )return -EINVAL ; -if (pos >= available) +if (pos >= available || !count)return 0 ;if (count > available - pos) count = available - pos; -if (copy_to_user (to, from + pos, count)) + ret =copy_to_user (to, from + pos, count); +if (ret == count)return -EFAULT ; + count -= ret; *ppos = pos + count;return count; }
_