Skip to content

Commit 81238b2

Browse files
author
Christoph Hellwig
committed
fs: implement kernel_write using __kernel_write
Consolidate the two in-kernel write helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_write, 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 a01ac27 commit 81238b2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

fs/read_write.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
499499
return -EINVAL;
500500
}
501501

502+
/* caller is responsible for file_start_write/file_end_write */
502503
ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
503504
{
504505
mm_segment_t old_fs;
@@ -528,16 +529,16 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
528529
ssize_t kernel_write(struct file *file, const void *buf, size_t count,
529530
loff_t *pos)
530531
{
531-
mm_segment_t old_fs;
532-
ssize_t res;
532+
ssize_t ret;
533533

534-
old_fs = get_fs();
535-
set_fs(KERNEL_DS);
536-
/* The cast to a user pointer is valid due to the set_fs() */
537-
res = vfs_write(file, (__force const char __user *)buf, count, pos);
538-
set_fs(old_fs);
534+
ret = rw_verify_area(WRITE, file, pos, count);
535+
if (ret)
536+
return ret;
539537

540-
return res;
538+
file_start_write(file);
539+
ret = __kernel_write(file, buf, count, pos);
540+
file_end_write(file);
541+
return ret;
541542
}
542543
EXPORT_SYMBOL(kernel_write);
543544

0 commit comments

Comments
 (0)