Skip to content

Commit 6209dd9

Browse files
author
Christoph Hellwig
committed
fs: implement kernel_read using __kernel_read
Consolidate the two in-kernel read helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_read, and an access_ok check that doesn't make sense for kernel buffers to start with. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent a1f9b1c commit 6209dd9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

fs/read_write.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
455455

456456
ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
457457
{
458-
mm_segment_t old_fs;
459-
ssize_t result;
458+
ssize_t ret;
460459

461-
old_fs = get_fs();
462-
set_fs(KERNEL_DS);
463-
/* The cast to a user pointer is valid due to the set_fs() */
464-
result = vfs_read(file, (void __user *)buf, count, pos);
465-
set_fs(old_fs);
466-
return result;
460+
ret = rw_verify_area(READ, file, pos, count);
461+
if (ret)
462+
return ret;
463+
return __kernel_read(file, buf, count, pos);
467464
}
468465
EXPORT_SYMBOL(kernel_read);
469466

0 commit comments

Comments
 (0)