Commit 14be2746 authored by Steven Rostedt's avatar Steven Rostedt Committed by Al Viro

libfs: make simple_read_from_buffer conventional

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.

[ simplification suggested by hpa]
[ fix count==0 handling]
Signed-off-by: default avatarSteven Rostedt <>
Cc: Al Viro <>
Cc: Theodore Ts'o <>
Cc: Ingo Molnar <>
Signed-off-by: default avatarH. Peter Anvin <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarAl Viro <>
parent 94a8d5ca
......@@ -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;
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