Skip to content

Commit f9835fa

Browse files
Al Virobrauner
authored andcommitted
make use of anon_inode_getfile_fmode()
["fallen through the cracks" misc stuff] A bunch of anon_inode_getfile() callers follow it with adjusting ->f_mode; we have a helper doing that now, so let's make use of it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Link: https://lore.kernel.org/r/20250118014434.GT1977892@ZenIV Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 822c115 commit f9835fa

File tree

7 files changed

+20
-39
lines changed

7 files changed

+20
-39
lines changed

arch/powerpc/platforms/pseries/papr-vpd.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,13 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc)
482482
goto free_blob;
483483
}
484484

485-
file = anon_inode_getfile("[papr-vpd]", &papr_vpd_handle_ops,
486-
(void *)blob, O_RDONLY);
485+
file = anon_inode_getfile_fmode("[papr-vpd]", &papr_vpd_handle_ops,
486+
(void *)blob, O_RDONLY,
487+
FMODE_LSEEK | FMODE_PREAD);
487488
if (IS_ERR(file)) {
488489
err = PTR_ERR(file);
489490
goto put_fd;
490491
}
491-
492-
file->f_mode |= FMODE_LSEEK | FMODE_PREAD;
493492
fd_install(fd, file);
494493
return fd;
495494
put_fd:

drivers/vfio/group.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,12 @@ static struct file *vfio_device_open_file(struct vfio_device *device)
266266
if (ret)
267267
goto err_free;
268268

269-
/*
270-
* We can't use anon_inode_getfd() because we need to modify
271-
* the f_mode flags directly to allow more than just ioctls
272-
*/
273-
filep = anon_inode_getfile("[vfio-device]", &vfio_device_fops,
274-
df, O_RDWR);
269+
filep = anon_inode_getfile_fmode("[vfio-device]", &vfio_device_fops,
270+
df, O_RDWR, FMODE_PREAD | FMODE_PWRITE);
275271
if (IS_ERR(filep)) {
276272
ret = PTR_ERR(filep);
277273
goto err_close_device;
278274
}
279-
280-
/*
281-
* TODO: add an anon_inode interface to do this.
282-
* Appears to be missing by lack of need rather than
283-
* explicitly prevented. Now there's need.
284-
*/
285-
filep->f_mode |= (FMODE_PREAD | FMODE_PWRITE);
286-
287275
/*
288276
* Use the pseudo fs inode on the device to link all mmaps
289277
* to the same address space, allowing us to unmap all vmas

fs/cachefiles/ondemand.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req,
317317
goto err_free_id;
318318
}
319319

320-
anon_file->file = anon_inode_getfile("[cachefiles]",
321-
&cachefiles_ondemand_fd_fops, object, O_WRONLY);
320+
anon_file->file = anon_inode_getfile_fmode("[cachefiles]",
321+
&cachefiles_ondemand_fd_fops, object,
322+
O_WRONLY, FMODE_PWRITE | FMODE_LSEEK);
322323
if (IS_ERR(anon_file->file)) {
323324
ret = PTR_ERR(anon_file->file);
324325
goto err_put_fd;
@@ -333,8 +334,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req,
333334
goto err_put_file;
334335
}
335336

336-
anon_file->file->f_mode |= FMODE_PWRITE | FMODE_LSEEK;
337-
338337
load = (void *)req->msg.data;
339338
load->fd = anon_file->fd;
340339
object->ondemand->ondemand_id = object_id;

fs/eventfd.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,13 @@ static int do_eventfd(unsigned int count, int flags)
406406
if (fd < 0)
407407
goto err;
408408

409-
file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags);
409+
file = anon_inode_getfile_fmode("[eventfd]", &eventfd_fops,
410+
ctx, flags, FMODE_NOWAIT);
410411
if (IS_ERR(file)) {
411412
put_unused_fd(fd);
412413
fd = PTR_ERR(file);
413414
goto err;
414415
}
415-
416-
file->f_mode |= FMODE_NOWAIT;
417416
fd_install(fd, file);
418417
return fd;
419418
err:

fs/signalfd.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,14 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)
277277
return ufd;
278278
}
279279

280-
file = anon_inode_getfile("[signalfd]", &signalfd_fops, ctx,
281-
O_RDWR | (flags & O_NONBLOCK));
280+
file = anon_inode_getfile_fmode("[signalfd]", &signalfd_fops,
281+
ctx, O_RDWR | (flags & O_NONBLOCK),
282+
FMODE_NOWAIT);
282283
if (IS_ERR(file)) {
283284
put_unused_fd(ufd);
284285
kfree(ctx);
285286
return PTR_ERR(file);
286287
}
287-
file->f_mode |= FMODE_NOWAIT;
288-
289288
fd_install(ufd, file);
290289
} else {
291290
CLASS(fd, f)(ufd);

fs/timerfd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
439439
return ufd;
440440
}
441441

442-
file = anon_inode_getfile("[timerfd]", &timerfd_fops, ctx,
443-
O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS));
442+
file = anon_inode_getfile_fmode("[timerfd]", &timerfd_fops, ctx,
443+
O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS),
444+
FMODE_NOWAIT);
444445
if (IS_ERR(file)) {
445446
put_unused_fd(ufd);
446447
kfree(ctx);
447448
return PTR_ERR(file);
448449
}
449450

450-
file->f_mode |= FMODE_NOWAIT;
451451
fd_install(ufd, file);
452452
return ufd;
453453
}

virt/kvm/kvm_main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,15 +4231,14 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)
42314231
if (fd < 0)
42324232
return fd;
42334233

4234-
file = anon_inode_getfile(name, &kvm_vcpu_stats_fops, vcpu, O_RDONLY);
4234+
file = anon_inode_getfile_fmode(name, &kvm_vcpu_stats_fops, vcpu,
4235+
O_RDONLY, FMODE_PREAD);
42354236
if (IS_ERR(file)) {
42364237
put_unused_fd(fd);
42374238
return PTR_ERR(file);
42384239
}
42394240

42404241
kvm_get_kvm(vcpu->kvm);
4241-
4242-
file->f_mode |= FMODE_PREAD;
42434242
fd_install(fd, file);
42444243

42454244
return fd;
@@ -5027,16 +5026,14 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)
50275026
if (fd < 0)
50285027
return fd;
50295028

5030-
file = anon_inode_getfile("kvm-vm-stats",
5031-
&kvm_vm_stats_fops, kvm, O_RDONLY);
5029+
file = anon_inode_getfile_fmode("kvm-vm-stats",
5030+
&kvm_vm_stats_fops, kvm, O_RDONLY, FMODE_PREAD);
50325031
if (IS_ERR(file)) {
50335032
put_unused_fd(fd);
50345033
return PTR_ERR(file);
50355034
}
50365035

50375036
kvm_get_kvm(kvm);
5038-
5039-
file->f_mode |= FMODE_PREAD;
50405037
fd_install(fd, file);
50415038

50425039
return fd;

0 commit comments

Comments
 (0)