export kernel_write(), convert open-coded instances
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 23 Feb 2013 19:51:48 +0000 (14:51 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 26 Feb 2013 07:46:11 +0000 (02:46 -0500)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/mtd/nand/nandsim.c
fs/ecryptfs/read_write.c
fs/splice.c
include/linux/fs.h
kernel/sysctl_binary.c

index 818b65c85d1293e5e7d31c0d5ad4116f81e54dec..8f30d385bfa3d82bdf47608b25d1f74ca5637137 100644 (file)
@@ -1408,40 +1408,32 @@ static void clear_memalloc(int memalloc)
                current->flags &= ~PF_MEMALLOC;
 }
 
-static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t *pos)
+static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
 {
-       mm_segment_t old_fs;
        ssize_t tx;
        int err, memalloc;
 
-       err = get_pages(ns, file, count, *pos);
+       err = get_pages(ns, file, count, pos);
        if (err)
                return err;
-       old_fs = get_fs();
-       set_fs(get_ds());
        memalloc = set_memalloc();
-       tx = vfs_read(file, (char __user *)buf, count, pos);
+       tx = kernel_read(file, pos, buf, count);
        clear_memalloc(memalloc);
-       set_fs(old_fs);
        put_pages(ns);
        return tx;
 }
 
-static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t *pos)
+static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
 {
-       mm_segment_t old_fs;
        ssize_t tx;
        int err, memalloc;
 
-       err = get_pages(ns, file, count, *pos);
+       err = get_pages(ns, file, count, pos);
        if (err)
                return err;
-       old_fs = get_fs();
-       set_fs(get_ds());
        memalloc = set_memalloc();
-       tx = vfs_write(file, (char __user *)buf, count, pos);
+       tx = kernel_write(file, buf, count, pos);
        clear_memalloc(memalloc);
-       set_fs(old_fs);
        put_pages(ns);
        return tx;
 }
@@ -1511,7 +1503,7 @@ static void read_page(struct nandsim *ns, int num)
                        if (do_read_error(ns, num))
                                return;
                        pos = (loff_t)ns->regs.row * ns->geom.pgszoob + ns->regs.column + ns->regs.off;
-                       tx = read_file(ns, ns->cfile, ns->buf.byte, num, &pos);
+                       tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos);
                        if (tx != num) {
                                NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx);
                                return;
@@ -1573,7 +1565,7 @@ static int prog_page(struct nandsim *ns, int num)
        u_char *pg_off;
 
        if (ns->cfile) {
-               loff_t off, pos;
+               loff_t off;
                ssize_t tx;
                int all;
 
@@ -1585,8 +1577,7 @@ static int prog_page(struct nandsim *ns, int num)
                        memset(ns->file_buf, 0xff, ns->geom.pgszoob);
                } else {
                        all = 0;
-                       pos = off;
-                       tx = read_file(ns, ns->cfile, pg_off, num, &pos);
+                       tx = read_file(ns, ns->cfile, pg_off, num, off);
                        if (tx != num) {
                                NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx);
                                return -1;
@@ -1595,16 +1586,15 @@ static int prog_page(struct nandsim *ns, int num)
                for (i = 0; i < num; i++)
                        pg_off[i] &= ns->buf.byte[i];
                if (all) {
-                       pos = (loff_t)ns->regs.row * ns->geom.pgszoob;
-                       tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, &pos);
+                       loff_t pos = (loff_t)ns->regs.row * ns->geom.pgszoob;
+                       tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, pos);
                        if (tx != ns->geom.pgszoob) {
                                NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx);
                                return -1;
                        }
                        ns->pages_written[ns->regs.row] = 1;
                } else {
-                       pos = off;
-                       tx = write_file(ns, ns->cfile, pg_off, num, &pos);
+                       tx = write_file(ns, ns->cfile, pg_off, num, off);
                        if (tx != num) {
                                NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx);
                                return -1;
index b2a34a192f4f50f23c6ea8658926afbbb8d2fcb8..6a160539cd23cabfd2d7ecfa8adb63409346e8d2 100644 (file)
@@ -40,16 +40,12 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
                         loff_t offset, size_t size)
 {
        struct file *lower_file;
-       mm_segment_t fs_save;
        ssize_t rc;
 
        lower_file = ecryptfs_inode_to_private(ecryptfs_inode)->lower_file;
        if (!lower_file)
                return -EIO;
-       fs_save = get_fs();
-       set_fs(get_ds());
-       rc = vfs_write(lower_file, data, size, &offset);
-       set_fs(fs_save);
+       rc = kernel_write(lower_file, data, size, offset);
        mark_inode_dirty_sync(ecryptfs_inode);
        return rc;
 }
index 963213d564032f836d2fe0957eeb2080e602a48e..718bd0056384688af6ead056156574638c0be6e9 100644 (file)
@@ -569,7 +569,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
        return res;
 }
 
-static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
+ssize_t kernel_write(struct file *file, const char *buf, size_t count,
                            loff_t pos)
 {
        mm_segment_t old_fs;
@@ -578,11 +578,12 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
        old_fs = get_fs();
        set_fs(get_ds());
        /* The cast to a user pointer is valid due to the set_fs() */
-       res = vfs_write(file, (const char __user *)buf, count, &pos);
+       res = vfs_write(file, (__force const char __user *)buf, count, &pos);
        set_fs(old_fs);
 
        return res;
 }
+EXPORT_SYMBOL(kernel_write);
 
 ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
                                 struct pipe_inode_info *pipe, size_t len,
index c766afd1e684e2ad68623e2641d5bdcbbddb24f6..d858363a7c173203309f62d92ce8570f1140a0ed 100644 (file)
@@ -2277,6 +2277,7 @@ static inline void i_readcount_inc(struct inode *inode)
 extern int do_pipe_flags(int *, int);
 
 extern int kernel_read(struct file *, loff_t, char *, unsigned long);
+extern ssize_t kernel_write(struct file *, const char *, size_t, loff_t);
 extern struct file * open_exec(const char *);
  
 /* fs/dcache.c -- generic fs support functions */
index 5a63844505015668ce88ec649f5586badf49dbbd..37f240fec37abff0eafe4a59f99ef4834f4926bf 100644 (file)
@@ -971,7 +971,6 @@ out:
 static ssize_t bin_intvec(struct file *file,
        void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
 {
-       mm_segment_t old_fs = get_fs();
        ssize_t copied = 0;
        char *buffer;
        ssize_t result;
@@ -984,13 +983,10 @@ static ssize_t bin_intvec(struct file *file,
        if (oldval && oldlen) {
                unsigned __user *vec = oldval;
                size_t length = oldlen / sizeof(*vec);
-               loff_t pos = 0;
                char *str, *end;
                int i;
 
-               set_fs(KERNEL_DS);
-               result = vfs_read(file, buffer, BUFSZ - 1, &pos);
-               set_fs(old_fs);
+               result = kernel_read(file, 0, buffer, BUFSZ - 1);
                if (result < 0)
                        goto out_kfree;
 
@@ -1017,7 +1013,6 @@ static ssize_t bin_intvec(struct file *file,
        if (newval && newlen) {
                unsigned __user *vec = newval;
                size_t length = newlen / sizeof(*vec);
-               loff_t pos = 0;
                char *str, *end;
                int i;
 
@@ -1033,9 +1028,7 @@ static ssize_t bin_intvec(struct file *file,
                        str += snprintf(str, end - str, "%lu\t", value);
                }
 
-               set_fs(KERNEL_DS);
-               result = vfs_write(file, buffer, str - buffer, &pos);
-               set_fs(old_fs);
+               result = kernel_write(file, buffer, str - buffer, 0);
                if (result < 0)
                        goto out_kfree;
        }
@@ -1049,7 +1042,6 @@ out:
 static ssize_t bin_ulongvec(struct file *file,
        void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
 {
-       mm_segment_t old_fs = get_fs();
        ssize_t copied = 0;
        char *buffer;
        ssize_t result;
@@ -1062,13 +1054,10 @@ static ssize_t bin_ulongvec(struct file *file,
        if (oldval && oldlen) {
                unsigned long __user *vec = oldval;
                size_t length = oldlen / sizeof(*vec);
-               loff_t pos = 0;
                char *str, *end;
                int i;
 
-               set_fs(KERNEL_DS);
-               result = vfs_read(file, buffer, BUFSZ - 1, &pos);
-               set_fs(old_fs);
+               result = kernel_read(file, 0, buffer, BUFSZ - 1);
                if (result < 0)
                        goto out_kfree;
 
@@ -1095,7 +1084,6 @@ static ssize_t bin_ulongvec(struct file *file,
        if (newval && newlen) {
                unsigned long __user *vec = newval;
                size_t length = newlen / sizeof(*vec);
-               loff_t pos = 0;
                char *str, *end;
                int i;
 
@@ -1111,9 +1099,7 @@ static ssize_t bin_ulongvec(struct file *file,
                        str += snprintf(str, end - str, "%lu\t", value);
                }
 
-               set_fs(KERNEL_DS);
-               result = vfs_write(file, buffer, str - buffer, &pos);
-               set_fs(old_fs);
+               result = kernel_write(file, buffer, str - buffer, 0);
                if (result < 0)
                        goto out_kfree;
        }
@@ -1127,19 +1113,15 @@ out:
 static ssize_t bin_uuid(struct file *file,
        void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
 {
-       mm_segment_t old_fs = get_fs();
        ssize_t result, copied = 0;
 
        /* Only supports reads */
        if (oldval && oldlen) {
-               loff_t pos = 0;
                char buf[40], *str = buf;
                unsigned char uuid[16];
                int i;
 
-               set_fs(KERNEL_DS);
-               result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
-               set_fs(old_fs);
+               result = kernel_read(file, 0, buf, sizeof(buf) - 1);
                if (result < 0)
                        goto out;
 
@@ -1175,18 +1157,14 @@ out:
 static ssize_t bin_dn_node_address(struct file *file,
        void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
 {
-       mm_segment_t old_fs = get_fs();
        ssize_t result, copied = 0;
 
        if (oldval && oldlen) {
-               loff_t pos = 0;
                char buf[15], *nodep;
                unsigned long area, node;
                __le16 dnaddr;
 
-               set_fs(KERNEL_DS);
-               result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
-               set_fs(old_fs);
+               result = kernel_read(file, 0, buf, sizeof(buf) - 1);
                if (result < 0)
                        goto out;
 
@@ -1215,7 +1193,6 @@ static ssize_t bin_dn_node_address(struct file *file,
        }
 
        if (newval && newlen) {
-               loff_t pos = 0;
                __le16 dnaddr;
                char buf[15];
                int len;
@@ -1232,9 +1209,7 @@ static ssize_t bin_dn_node_address(struct file *file,
                                le16_to_cpu(dnaddr) >> 10,
                                le16_to_cpu(dnaddr) & 0x3ff);
 
-               set_fs(KERNEL_DS);
-               result = vfs_write(file, buf, len, &pos);
-               set_fs(old_fs);
+               result = kernel_write(file, buf, len, 0);
                if (result < 0)
                        goto out;
        }