Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Al Viro and committed by
Christian Brauner
f9835fa1 822c1159

+20 -39
+3 -4
arch/powerpc/platforms/pseries/papr-vpd.c
··· 482 482 goto free_blob; 483 483 } 484 484 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); 487 488 if (IS_ERR(file)) { 488 489 err = PTR_ERR(file); 489 490 goto put_fd; 490 491 } 491 - 492 - file->f_mode |= FMODE_LSEEK | FMODE_PREAD; 493 492 fd_install(fd, file); 494 493 return fd; 495 494 put_fd:
+2 -14
drivers/vfio/group.c
··· 266 266 if (ret) 267 267 goto err_free; 268 268 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); 275 271 if (IS_ERR(filep)) { 276 272 ret = PTR_ERR(filep); 277 273 goto err_close_device; 278 274 } 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 - 287 275 /* 288 276 * Use the pseudo fs inode on the device to link all mmaps 289 277 * to the same address space, allowing us to unmap all vmas
+3 -4
fs/cachefiles/ondemand.c
··· 317 317 goto err_free_id; 318 318 } 319 319 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); 322 323 if (IS_ERR(anon_file->file)) { 323 324 ret = PTR_ERR(anon_file->file); 324 325 goto err_put_fd; ··· 333 332 ret = -EEXIST; 334 333 goto err_put_file; 335 334 } 336 - 337 - anon_file->file->f_mode |= FMODE_PWRITE | FMODE_LSEEK; 338 335 339 336 load = (void *)req->msg.data; 340 337 load->fd = anon_file->fd;
+2 -3
fs/eventfd.c
··· 406 406 if (fd < 0) 407 407 goto err; 408 408 409 - file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags); 409 + file = anon_inode_getfile_fmode("[eventfd]", &eventfd_fops, 410 + ctx, flags, FMODE_NOWAIT); 410 411 if (IS_ERR(file)) { 411 412 put_unused_fd(fd); 412 413 fd = PTR_ERR(file); 413 414 goto err; 414 415 } 415 - 416 - file->f_mode |= FMODE_NOWAIT; 417 416 fd_install(fd, file); 418 417 return fd; 419 418 err:
+3 -4
fs/signalfd.c
··· 277 277 return ufd; 278 278 } 279 279 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); 282 283 if (IS_ERR(file)) { 283 284 put_unused_fd(ufd); 284 285 kfree(ctx); 285 286 return PTR_ERR(file); 286 287 } 287 - file->f_mode |= FMODE_NOWAIT; 288 - 289 288 fd_install(ufd, file); 290 289 } else { 291 290 CLASS(fd, f)(ufd);
+3 -3
fs/timerfd.c
··· 439 439 return ufd; 440 440 } 441 441 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); 444 445 if (IS_ERR(file)) { 445 446 put_unused_fd(ufd); 446 447 kfree(ctx); 447 448 return PTR_ERR(file); 448 449 } 449 450 450 - file->f_mode |= FMODE_NOWAIT; 451 451 fd_install(ufd, file); 452 452 return ufd; 453 453 }
+4 -7
virt/kvm/kvm_main.c
··· 4231 4231 if (fd < 0) 4232 4232 return fd; 4233 4233 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); 4235 4236 if (IS_ERR(file)) { 4236 4237 put_unused_fd(fd); 4237 4238 return PTR_ERR(file); 4238 4239 } 4239 4240 4240 4241 kvm_get_kvm(vcpu->kvm); 4241 - 4242 - file->f_mode |= FMODE_PREAD; 4243 4242 fd_install(fd, file); 4244 4243 4245 4244 return fd; ··· 5026 5027 if (fd < 0) 5027 5028 return fd; 5028 5029 5029 - file = anon_inode_getfile("kvm-vm-stats", 5030 - &kvm_vm_stats_fops, kvm, O_RDONLY); 5030 + file = anon_inode_getfile_fmode("kvm-vm-stats", 5031 + &kvm_vm_stats_fops, kvm, O_RDONLY, FMODE_PREAD); 5031 5032 if (IS_ERR(file)) { 5032 5033 put_unused_fd(fd); 5033 5034 return PTR_ERR(file); 5034 5035 } 5035 5036 5036 5037 kvm_get_kvm(kvm); 5037 - 5038 - file->f_mode |= FMODE_PREAD; 5039 5038 fd_install(fd, file); 5040 5039 5041 5040 return fd;