Skip to content

Commit 581bfce

Browse files
committed
Merge branch 'work.set_fs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull more set_fs removal from Al Viro: "Christoph's 'use kernel_read and friends rather than open-coding set_fs()' series" * 'work.set_fs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: fs: unexport vfs_readv and vfs_writev fs: unexport vfs_read and vfs_write fs: unexport __vfs_read/__vfs_write lustre: switch to kernel_write gadget/f_mass_storage: stop messing with the address limit mconsole: switch to kernel_read btrfs: switch write_buf to kernel_write net/9p: switch p9_fd_read to kernel_write mm/nommu: switch do_mmap_private to kernel_read serial2002: switch serial2002_tty_write to kernel_{read/write} fs: make the buf argument to __kernel_write a void pointer fs: fix kernel_write prototype fs: fix kernel_read prototype fs: move kernel_read to fs/read_write.c fs: move kernel_write to fs/read_write.c autofs4: switch autofs4_write to __kernel_write ashmem: switch to ->read_iter
2 parents cc73fee + 9725d4c commit 581bfce

File tree

31 files changed

+147
-236
lines changed

31 files changed

+147
-236
lines changed

arch/mips/kernel/elf.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
8787
bool elf32;
8888
u32 flags;
8989
int ret;
90+
loff_t pos;
9091

9192
elf32 = ehdr->e32.e_ident[EI_CLASS] == ELFCLASS32;
9293
flags = elf32 ? ehdr->e32.e_flags : ehdr->e64.e_flags;
@@ -108,21 +109,16 @@ int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
108109

109110
if (phdr32->p_filesz < sizeof(abiflags))
110111
return -EINVAL;
111-
112-
ret = kernel_read(elf, phdr32->p_offset,
113-
(char *)&abiflags,
114-
sizeof(abiflags));
112+
pos = phdr32->p_offset;
115113
} else {
116114
if (phdr64->p_type != PT_MIPS_ABIFLAGS)
117115
return 0;
118116
if (phdr64->p_filesz < sizeof(abiflags))
119117
return -EINVAL;
120-
121-
ret = kernel_read(elf, phdr64->p_offset,
122-
(char *)&abiflags,
123-
sizeof(abiflags));
118+
pos = phdr64->p_offset;
124119
}
125120

121+
ret = kernel_read(elf, &abiflags, sizeof(abiflags), &pos);
126122
if (ret < 0)
127123
return ret;
128124
if (ret != sizeof(abiflags))

arch/um/drivers/mconsole_kern.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,7 @@ void mconsole_proc(struct mc_request *req)
148148
}
149149

150150
do {
151-
loff_t pos = file->f_pos;
152-
mm_segment_t old_fs = get_fs();
153-
set_fs(KERNEL_DS);
154-
len = vfs_read(file, buf, PAGE_SIZE - 1, &pos);
155-
set_fs(old_fs);
156-
file->f_pos = pos;
151+
len = kernel_read(file, buf, PAGE_SIZE - 1, &file->f_pos);
157152
if (len < 0) {
158153
mconsole_reply(req, "Read of file failed", 1, 0);
159154
goto out_free;

arch/x86/ia32/ia32_aout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ static int load_aout_library(struct file *file)
407407
unsigned long bss, start_addr, len, error;
408408
int retval;
409409
struct exec ex;
410-
410+
loff_t pos = 0;
411411

412412
retval = -ENOEXEC;
413-
error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
413+
error = kernel_read(file, &ex, sizeof(ex), &pos);
414414
if (error != sizeof(ex))
415415
goto out;
416416

drivers/media/pci/cx25821/cx25821-audio-upstream.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int cx25821_get_audio_data(struct cx25821_dev *dev,
277277
p = (char *)dev->_audiodata_buf_virt_addr + frame_offset;
278278

279279
for (i = 0; i < dev->_audio_lines_count; i++) {
280-
int n = kernel_read(file, file_offset, mybuf, AUDIO_LINE_SIZE);
280+
int n = kernel_read(file, mybuf, AUDIO_LINE_SIZE, &file_offset);
281281
if (n < AUDIO_LINE_SIZE) {
282282
pr_info("Done: exit %s() since no more bytes to read from Audio file\n",
283283
__func__);
@@ -290,7 +290,6 @@ static int cx25821_get_audio_data(struct cx25821_dev *dev,
290290
memcpy(p, mybuf, n);
291291
p += n;
292292
}
293-
file_offset += n;
294293
}
295294
dev->_audioframe_count++;
296295
fput(file);
@@ -318,7 +317,7 @@ static int cx25821_openfile_audio(struct cx25821_dev *dev,
318317
{
319318
char *p = (void *)dev->_audiodata_buf_virt_addr;
320319
struct file *file;
321-
loff_t offset;
320+
loff_t file_offset = 0;
322321
int i, j;
323322

324323
file = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0);
@@ -328,11 +327,11 @@ static int cx25821_openfile_audio(struct cx25821_dev *dev,
328327
return PTR_ERR(file);
329328
}
330329

331-
for (j = 0, offset = 0; j < NUM_AUDIO_FRAMES; j++) {
330+
for (j = 0; j < NUM_AUDIO_FRAMES; j++) {
332331
for (i = 0; i < dev->_audio_lines_count; i++) {
333332
char buf[AUDIO_LINE_SIZE];
334-
int n = kernel_read(file, offset, buf,
335-
AUDIO_LINE_SIZE);
333+
loff_t offset = file_offset;
334+
int n = kernel_read(file, buf, AUDIO_LINE_SIZE, &file_offset);
336335

337336
if (n < AUDIO_LINE_SIZE) {
338337
pr_info("Done: exit %s() since no more bytes to read from Audio file\n",
@@ -344,8 +343,6 @@ static int cx25821_openfile_audio(struct cx25821_dev *dev,
344343

345344
if (p)
346345
memcpy(p + offset, buf, n);
347-
348-
offset += n;
349346
}
350347
dev->_audioframe_count++;
351348
}

drivers/mtd/nand/nandsim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_
13561356
if (err)
13571357
return err;
13581358
noreclaim_flag = memalloc_noreclaim_save();
1359-
tx = kernel_read(file, pos, buf, count);
1359+
tx = kernel_read(file, buf, count, &pos);
13601360
memalloc_noreclaim_restore(noreclaim_flag);
13611361
put_pages(ns);
13621362
return tx;
@@ -1372,7 +1372,7 @@ static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size
13721372
if (err)
13731373
return err;
13741374
noreclaim_flag = memalloc_noreclaim_save();
1375-
tx = kernel_write(file, buf, count, pos);
1375+
tx = kernel_write(file, buf, count, &pos);
13761376
memalloc_noreclaim_restore(noreclaim_flag);
13771377
put_pages(ns);
13781378
return tx;

drivers/staging/android/ashmem.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,9 @@ static int ashmem_release(struct inode *ignored, struct file *file)
294294
return 0;
295295
}
296296

297-
/**
298-
* ashmem_read() - Reads a set of bytes from an Ashmem-enabled file
299-
* @file: The associated backing file.
300-
* @buf: The buffer of data being written to
301-
* @len: The number of bytes being read
302-
* @pos: The position of the first byte to read.
303-
*
304-
* Return: 0 if successful, or another return code if not.
305-
*/
306-
static ssize_t ashmem_read(struct file *file, char __user *buf,
307-
size_t len, loff_t *pos)
297+
static ssize_t ashmem_read_iter(struct kiocb *iocb, struct iov_iter *iter)
308298
{
309-
struct ashmem_area *asma = file->private_data;
299+
struct ashmem_area *asma = iocb->ki_filp->private_data;
310300
int ret = 0;
311301

312302
mutex_lock(&ashmem_mutex);
@@ -320,20 +310,17 @@ static ssize_t ashmem_read(struct file *file, char __user *buf,
320310
goto out_unlock;
321311
}
322312

323-
mutex_unlock(&ashmem_mutex);
324-
325313
/*
326314
* asma and asma->file are used outside the lock here. We assume
327315
* once asma->file is set it will never be changed, and will not
328316
* be destroyed until all references to the file are dropped and
329317
* ashmem_release is called.
330318
*/
331-
ret = __vfs_read(asma->file, buf, len, pos);
332-
if (ret >= 0)
333-
/** Update backing file pos, since f_ops->read() doesn't */
334-
asma->file->f_pos = *pos;
335-
return ret;
336-
319+
mutex_unlock(&ashmem_mutex);
320+
ret = vfs_iter_read(asma->file, iter, &iocb->ki_pos, 0);
321+
mutex_lock(&ashmem_mutex);
322+
if (ret > 0)
323+
asma->file->f_pos = iocb->ki_pos;
337324
out_unlock:
338325
mutex_unlock(&ashmem_mutex);
339326
return ret;
@@ -834,7 +821,7 @@ static const struct file_operations ashmem_fops = {
834821
.owner = THIS_MODULE,
835822
.open = ashmem_open,
836823
.release = ashmem_release,
837-
.read = ashmem_read,
824+
.read_iter = ashmem_read_iter,
838825
.llseek = ashmem_llseek,
839826
.mmap = ashmem_mmap,
840827
.unlocked_ioctl = ashmem_ioctl,

drivers/staging/comedi/drivers/serial2002.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,8 @@ static long serial2002_tty_ioctl(struct file *f, unsigned int op,
106106

107107
static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
108108
{
109-
const char __user *p = (__force const char __user *)buf;
110-
int result;
111-
loff_t offset = 0;
112-
mm_segment_t oldfs;
113-
114-
oldfs = get_fs();
115-
set_fs(KERNEL_DS);
116-
result = __vfs_write(f, p, count, &offset);
117-
set_fs(oldfs);
118-
return result;
109+
loff_t pos = 0;
110+
return kernel_write(f, buf, count, &pos);
119111
}
120112

121113
static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
@@ -148,19 +140,14 @@ static int serial2002_tty_read(struct file *f, int timeout)
148140
{
149141
unsigned char ch;
150142
int result;
143+
loff_t pos = 0;
151144

152145
result = -1;
153146
if (!IS_ERR(f)) {
154-
mm_segment_t oldfs;
155-
char __user *p = (__force char __user *)&ch;
156-
loff_t offset = 0;
157-
158-
oldfs = get_fs();
159-
set_fs(KERNEL_DS);
160147
if (f->f_op->poll) {
161148
serial2002_tty_read_poll_wait(f, timeout);
162149

163-
if (__vfs_read(f, p, 1, &offset) == 1)
150+
if (kernel_read(f, &ch, 1, &pos) == 1)
164151
result = ch;
165152
} else {
166153
/* Device does not support poll, busy wait */
@@ -171,14 +158,13 @@ static int serial2002_tty_read(struct file *f, int timeout)
171158
if (retries >= timeout)
172159
break;
173160

174-
if (__vfs_read(f, p, 1, &offset) == 1) {
161+
if (kernel_read(f, &ch, 1, &pos) == 1) {
175162
result = ch;
176163
break;
177164
}
178165
usleep_range(100, 1000);
179166
}
180167
}
181-
set_fs(oldfs);
182168
}
183169
return result;
184170
}

drivers/staging/lustre/lnet/libcfs/tracefile.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
731731
__LASSERT_TAGE_INVARIANT(tage);
732732

733733
buf = kmap(tage->page);
734-
rc = vfs_write(filp, (__force const char __user *)buf,
735-
tage->used, &filp->f_pos);
734+
rc = kernel_write(filp, buf, tage->used, &filp->f_pos);
736735
kunmap(tage->page);
737736

738737
if (rc != (int)tage->used) {
@@ -976,7 +975,6 @@ static int tracefiled(void *arg)
976975
struct tracefiled_ctl *tctl = arg;
977976
struct cfs_trace_page *tage;
978977
struct cfs_trace_page *tmp;
979-
mm_segment_t __oldfs;
980978
struct file *filp;
981979
char *buf;
982980
int last_loop = 0;
@@ -1014,8 +1012,6 @@ static int tracefiled(void *arg)
10141012
__LASSERT(list_empty(&pc.pc_pages));
10151013
goto end_loop;
10161014
}
1017-
__oldfs = get_fs();
1018-
set_fs(get_ds());
10191015

10201016
list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
10211017
static loff_t f_pos;
@@ -1028,8 +1024,7 @@ static int tracefiled(void *arg)
10281024
f_pos = i_size_read(file_inode(filp));
10291025

10301026
buf = kmap(tage->page);
1031-
rc = vfs_write(filp, (__force const char __user *)buf,
1032-
tage->used, &f_pos);
1027+
rc = kernel_write(filp, buf, tage->used, &f_pos);
10331028
kunmap(tage->page);
10341029

10351030
if (rc != (int)tage->used) {
@@ -1040,7 +1035,6 @@ static int tracefiled(void *arg)
10401035
break;
10411036
}
10421037
}
1043-
set_fs(__oldfs);
10441038

10451039
filp_close(filp, NULL);
10461040
put_pages_on_daemon_list(&pc);

drivers/staging/lustre/lustre/obdclass/kernelcomm.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int libcfs_kkuc_msg_put(struct file *filp, void *payload)
5252
struct kuc_hdr *kuch = (struct kuc_hdr *)payload;
5353
ssize_t count = kuch->kuc_msglen;
5454
loff_t offset = 0;
55-
mm_segment_t fs;
5655
int rc = -ENXIO;
5756

5857
if (IS_ERR_OR_NULL(filp))
@@ -63,18 +62,14 @@ int libcfs_kkuc_msg_put(struct file *filp, void *payload)
6362
return rc;
6463
}
6564

66-
fs = get_fs();
67-
set_fs(KERNEL_DS);
6865
while (count > 0) {
69-
rc = vfs_write(filp, (void __force __user *)payload,
70-
count, &offset);
66+
rc = kernel_write(filp, payload, count, &offset);
7167
if (rc < 0)
7268
break;
7369
count -= rc;
7470
payload += rc;
7571
rc = 0;
7672
}
77-
set_fs(fs);
7873

7974
if (rc < 0)
8075
CWARN("message send failed (%d)\n", rc);

drivers/target/target_core_alua.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,13 +896,14 @@ static int core_alua_write_tpg_metadata(
896896
u32 md_buf_len)
897897
{
898898
struct file *file = filp_open(path, O_RDWR | O_CREAT | O_TRUNC, 0600);
899+
loff_t pos = 0;
899900
int ret;
900901

901902
if (IS_ERR(file)) {
902903
pr_err("filp_open(%s) for ALUA metadata failed\n", path);
903904
return -ENODEV;
904905
}
905-
ret = kernel_write(file, md_buf, md_buf_len, 0);
906+
ret = kernel_write(file, md_buf, md_buf_len, &pos);
906907
if (ret < 0)
907908
pr_err("Error writing ALUA metadata file: %s\n", path);
908909
fput(file);

0 commit comments

Comments
 (0)