summaryrefslogtreecommitdiff
path: root/fs/read_write.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-05-07 19:33:03 +0200
committerChristoph Hellwig <hch@lst.de>2020-07-08 08:27:56 +0200
commit81238b2cff1469ff5b94390d026cd075105d6dcd (patch)
tree5011d4dfb86cad5ac8fd10fb8fb4237cefe0ad19 /fs/read_write.c
parenta01ac27be4729f80176a45c54611b768dfbdc840 (diff)
downloadlinux-rpi-81238b2cff1469ff5b94390d026cd075105d6dcd.tar.gz
linux-rpi-81238b2cff1469ff5b94390d026cd075105d6dcd.tar.bz2
linux-rpi-81238b2cff1469ff5b94390d026cd075105d6dcd.zip
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 <hch@lst.de>
Diffstat (limited to 'fs/read_write.c')
-rw-r--r--fs/read_write.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/fs/read_write.c b/fs/read_write.c
index 8f9fc05990ae..5110cd1e6e27 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -499,6 +499,7 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
return -EINVAL;
}
+/* caller is responsible for file_start_write/file_end_write */
ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
{
mm_segment_t old_fs;
@@ -528,16 +529,16 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
ssize_t kernel_write(struct file *file, const void *buf, size_t count,
loff_t *pos)
{
- mm_segment_t old_fs;
- ssize_t res;
+ ssize_t ret;
- old_fs = get_fs();
- set_fs(KERNEL_DS);
- /* The cast to a user pointer is valid due to the set_fs() */
- res = vfs_write(file, (__force const char __user *)buf, count, pos);
- set_fs(old_fs);
+ ret = rw_verify_area(WRITE, file, pos, count);
+ if (ret)
+ return ret;
- return res;
+ file_start_write(file);
+ ret = __kernel_write(file, buf, count, pos);
+ file_end_write(file);
+ return ret;
}
EXPORT_SYMBOL(kernel_write);