summaryrefslogtreecommitdiffstats
path: root/fs/read_write.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-05-08 08:54:16 +0200
committerChristoph Hellwig <hch@lst.de>2020-07-08 08:27:56 +0200
commit61a707c543e2afe3aa7e88f87267c5dafa4b5afa (patch)
tree0890bd5d37503f57d3dca76d90a320eda56a802a /fs/read_write.c
parent53ad86266bda973b526078227997ca3fcb92c9be (diff)
downloadlinux-61a707c543e2afe3aa7e88f87267c5dafa4b5afa.tar.gz
linux-61a707c543e2afe3aa7e88f87267c5dafa4b5afa.tar.bz2
linux-61a707c543e2afe3aa7e88f87267c5dafa4b5afa.zip
fs: add a __kernel_read helper
This is the counterpart to __kernel_write, and skip the rw_verify_area call compared to kernel_read. Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/read_write.c')
-rw-r--r--fs/read_write.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/fs/read_write.c b/fs/read_write.c
index 96e8e354f99b..21c9d90a257e 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -430,6 +430,29 @@ ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,
return -EINVAL;
}
+ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
+{
+ mm_segment_t old_fs = get_fs();
+ ssize_t ret;
+
+ if (WARN_ON_ONCE(!(file->f_mode & FMODE_READ)))
+ return -EINVAL;
+ if (!(file->f_mode & FMODE_CAN_READ))
+ return -EINVAL;
+
+ if (count > MAX_RW_COUNT)
+ count = MAX_RW_COUNT;
+ set_fs(KERNEL_DS);
+ ret = __vfs_read(file, (void __user *)buf, count, pos);
+ set_fs(old_fs);
+ if (ret > 0) {
+ fsnotify_access(file);
+ add_rchar(current, ret);
+ }
+ inc_syscr(current);
+ return ret;
+}
+
ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
{
mm_segment_t old_fs;