From: Steven Rostedt Date: Fri, 18 Sep 2009 20:05:42 +0000 (-0700) Subject: libfs: make simple_read_from_buffer conventional X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=14be27460e4722d7135de3c46d043b4fc4382247;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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. [akpm@linux-foundation.org: simplification suggested by hpa] [hpa@zytor.com: fix count==0 handling] Signed-off-by: Steven Rostedt Cc: Al Viro Cc: Theodore Ts'o Cc: Ingo Molnar Signed-off-by: H. Peter Anvin Signed-off-by: Andrew Morton Signed-off-by: Al Viro --- diff --git a/fs/libfs.c b/fs/libfs.c index dcec3d3ea64f..662a28e4f667 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -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; }