Skip to content

Commit

Permalink
libfs: make simple_read_from_buffer conventional
Browse files Browse the repository at this point in the history
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]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
rostedt authored and Al Viro committed Sep 24, 2009
1 parent 94a8d5c commit 14be274
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/libfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,18 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
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;
}
Expand Down

0 comments on commit 14be274

Please sign in to comment.