Rename get_unused_fd_flags to get_unused_fd
Subsystems (57)
PATCH 1/1 Rename get_unused_fd_flags to get_unused_fd
The current name can be misread as having something to do with unused *flags*. And without a get_unused_fd() function already floating around, it's easy to resolve this by dropping the suffix.
---
I'm not sure if there's any appetite for refactors like this: they're tedious for sure. I couldn't find any discouragement in the docs though, so I figured I'd just post the patch and let it find me.
Anyways, if anyone wants to regenerate the patch for some reason it's easy enough using [1] (might take a minute or two).
[1] find . -type f -name '*.[ch]' | xargs sed -i 's/\bget_unused_fd_flags\b/get_unused_fd/g' This does miss references in two files, those being
1. Documentation/driver-api/sync_file.rst
2. rust/kernel/fs/file.rs
Documentation/driver-api/sync_file.rst | 2 +- arch/powerpc/platforms/cell/spufs/inode.c | 4 ++-- arch/powerpc/platforms/pseries/papr-vpd.c | 2 +- drivers/android/binder.c | 2 +- drivers/char/tpm/tpm_vtpm_proxy.c | 2 +- drivers/dma-buf/dma-buf.c | 4 ++-- drivers/dma-buf/sw_sync.c | 2 +- drivers/dma-buf/sync_file.c | 2 +- drivers/gpio/gpiolib-cdev.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/drm_atomic_uapi.c | 2 +- drivers/gpu/drm/drm_lease.c | 2 +- drivers/gpu/drm/drm_prime.c | 2 +- drivers/gpu/drm/drm_syncobj.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/msm/msm_gem_submit.c | 2 +- drivers/gpu/drm/virtio/virtgpu_submit.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 +- drivers/hv/mshv_root_main.c | 2 +- drivers/infiniband/core/rdma_core.c | 2 +- drivers/iommu/iommufd/eventq.c | 2 +- drivers/iommu/iommufd/selftest.c | 2 +- drivers/media/mc/mc-request.c | 2 +- drivers/misc/ntsync.c | 2 +- drivers/tty/pty.c | 2 +- drivers/vfio/group.c | 2 +- drivers/vfio/vfio_main.c | 2 +- drivers/virt/nitro_enclaves/ne_misc_dev.c | 2 +- fs/anon_inodes.c | 2 +- fs/autofs/dev-ioctl.c | 2 +- fs/bcachefs/thread_with_file.c | 2 +- fs/cachefiles/ondemand.c | 2 +- fs/eventfd.c | 2 +- fs/eventpoll.c | 2 +- fs/exec.c | 2 +- fs/file.c | 14 +++++++------- fs/init.c | 2 +- fs/namespace.c | 6 +++--- fs/notify/fanotify/fanotify_user.c | 4 ++-- fs/open.c | 2 +- fs/pipe.c | 4 ++-- fs/signalfd.c | 2 +- fs/timerfd.c | 2 +- fs/userfaultfd.c | 2 +- fs/xfs/xfs_handle.c | 2 +- include/linux/file.h | 6 +++--- include/uapi/linux/nitro_enclaves.h | 2 +- io_uring/io_uring.c | 2 +- io_uring/net.c | 4 ++-- io_uring/openclose.c | 2 +- ipc/mqueue.c | 2 +- kernel/bpf/bpf_iter.c | 2 +- kernel/bpf/syscall.c | 2 +- kernel/bpf/token.c | 2 +- kernel/events/core.c | 2 +- kernel/seccomp.c | 2 +- mm/memfd.c | 2 +- mm/secretmem.c | 2 +- net/handshake/netlink.c | 2 +- net/kcm/kcmsock.c | 2 +- net/sctp/socket.c | 2 +- net/socket.c | 8 ++++---- net/unix/af_unix.c | 2 +- rust/kernel/fs/file.rs | 10 +++++----- sound/core/compress_offload.c | 4 ++-- virt/kvm/guest_memfd.c | 2 +- virt/kvm/kvm_main.c | 6 +++--- 69 files changed, 97 insertions(+), 97 deletions(-)
Documentation/driver-api/sync_file.rst +1 -1
@@ -54,7 +54,7 @@ The caller pass the out-fence and gets back the sync_file. That is just the first step, next it needs to install an fd on sync_file->file. So it gets an fd:: - fd = get_unused_fd_flags(O_CLOEXEC); + fd = get_unused_fd(O_CLOEXEC); and installs it on sync_file->file::
arch/powerpc/platforms/cell/spufs/inode.c +2 -2
@@ -281,7 +281,7 @@ static int spufs_context_open(const struct path *path)int ret;struct file *filp; - ret =get_unused_fd_flags (0 ); + ret =get_unused_fd (0 );if (ret <0 )return ret;
@@ -497,7 +497,7 @@ static int spufs_gang_open(const struct path *path)int ret;struct file *filp; - ret =get_unused_fd_flags (0 ); + ret =get_unused_fd (0 );if (ret <0 )return ret;
arch/powerpc/platforms/pseries/papr-vpd.c +1 -1
@@ -476,7 +476,7 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc)if (IS_ERR (blob))return PTR_ERR (blob); - fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); + fd =get_unused_fd (O_RDONLY |O_CLOEXEC );if (fd <0 ) { err = fd; goto free_blob;
drivers/android/binder.c +1 -1
@@ -4618,7 +4618,7 @@ static int binder_apply_fd_fixups(struct binder_proc *proc,int ret =0 ;list_for_each_entry (fixup, &t->fd_fixups, fixup_entry) { -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { binder_debug(BINDER_DEBUG_TRANSACTION,
drivers/char/tpm/tpm_vtpm_proxy.c +1 -1
@@ -546,7 +546,7 @@ static struct file *vtpm_proxy_create_device( proxy_dev->flags = vtpm_new_dev->flags;/* setup an anonymous file for the server-side */ - fd =get_unused_fd_flags (O_RDWR ); + fd =get_unused_fd (O_RDWR );if (fd <0 ) { rc = fd; goto err_delete_proxy_dev;
drivers/dma-buf/dma-buf.c +2 -2
@@ -368,7 +368,7 @@ static long dma_buf_export_sync_file(struct dma_buf *dmabuf,if ((arg.flags &DMA_BUF_SYNC_RW ) ==0 )return -EINVAL ; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
@@ -719,7 +719,7 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)if (!dmabuf || !dmabuf->file)return -EINVAL ; - fd =get_unused_fd_flags (flags); + fd =get_unused_fd (flags);if (fd <0 )return fd;
drivers/dma-buf/sw_sync.c +1 -1
@@ -359,7 +359,7 @@ static int sw_sync_debugfs_release(struct inode *inode, struct file *file)static long sw_sync_ioctl_create_fence (struct sync_timeline *obj,unsigned long arg) { -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );int err;struct sync_pt *pt;struct sync_file *sync_file;
drivers/dma-buf/sync_file.c +1 -1
@@ -207,7 +207,7 @@ static __poll_t sync_file_poll(struct file *file, poll_table *wait)static long sync_file_ioctl_merge (struct sync_file *sync_file,unsigned long arg) { -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );int err;struct sync_file *fence2, *fence3;struct sync_merge_data data;
drivers/gpio/gpiolib-cdev.c +3 -3
@@ -377,7 +377,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) offset); } - fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); + fd =get_unused_fd (O_RDONLY |O_CLOEXEC );if (fd <0 ) { ret = fd; goto out_free_lh;
@@ -1729,7 +1729,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)if (ret) goto out_free_linereq; - fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); + fd =get_unused_fd (O_RDONLY |O_CLOEXEC );if (fd <0 ) { ret = fd; goto out_free_linereq;
@@ -2154,7 +2154,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) le->irq = irq; - fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); + fd =get_unused_fd (O_RDONLY |O_CLOEXEC );if (fd <0 ) { ret = fd; goto out_free_le;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -1596,7 +1596,7 @@ int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,return r;case AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD : - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) {dma_fence_put (fence);return fd;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -1858,7 +1858,7 @@ static int criu_get_prime_handle(struct kgd_mem *mem,return ret; } - ret =get_unused_fd_flags (flags); + ret =get_unused_fd (flags);if (ret <0 ) {pr_err ("dmabuf create fd failed, ret:%d\n" , ret); goto out_free_dmabuf;
drivers/gpu/drm/drm_atomic_uapi.c +1 -1
@@ -1178,7 +1178,7 @@ struct drm_out_fence_state {static int setup_out_fence (struct drm_out_fence_state *fence_state,struct dma_fence *fence) { - fence_state->fd =get_unused_fd_flags (O_CLOEXEC ); + fence_state->fd =get_unused_fd (O_CLOEXEC );if (fence_state->fd <0 )return fence_state->fd;
drivers/gpu/drm/drm_lease.c +1 -1
@@ -530,7 +530,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, }/* Allocate a file descriptor for the lease */ - fd =get_unused_fd_flags (cl->flags & (O_CLOEXEC |O_NONBLOCK )); + fd =get_unused_fd (cl->flags & (O_CLOEXEC |O_NONBLOCK ));if (fd <0 ) {idr_destroy (&leases); ret = fd;
drivers/gpu/drm/drm_prime.c +1 -1
@@ -510,7 +510,7 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev, int *prime_fd) {struct dma_buf *dmabuf; -int fd =get_unused_fd_flags (flags); +int fd =get_unused_fd (flags);if (fd <0 )return fd;
drivers/gpu/drm/drm_syncobj.c +2 -2
@@ -674,7 +674,7 @@ int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd)struct file *file;int fd; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
@@ -767,7 +767,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,int ret;struct dma_fence *fence;struct sync_file *sync_file; -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
@@ -505,7 +505,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, }if (args->flags &ETNA_SUBMIT_FENCE_FD_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); + out_fence_fd =get_unused_fd (O_CLOEXEC );if (out_fence_fd <0 ) { ret = out_fence_fd; goto err_submit_cmds;
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
@@ -3432,7 +3432,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,#undef IN_FENCESif (args->flags &I915_EXEC_FENCE_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); + out_fence_fd =get_unused_fd (O_CLOEXEC );if (out_fence_fd <0 ) { err = out_fence_fd; goto err_in_fence;
drivers/gpu/drm/msm/msm_gem_submit.c +1 -1
@@ -686,7 +686,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, ring = gpu->rb[queue->ring_nr];if (args->flags &MSM_SUBMIT_FENCE_FD_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); + out_fence_fd =get_unused_fd (O_CLOEXEC );if (out_fence_fd <0 ) { ret = out_fence_fd; goto out_post_unlock;
drivers/gpu/drm/virtio/virtgpu_submit.c +1 -1
@@ -418,7 +418,7 @@ static int virtio_gpu_init_submit(struct virtio_gpu_submit *submit,return PTR_ERR (submit->buf);if (exbuf->flags &VIRTGPU_EXECBUF_FENCE_FD_OUT ) { - err =get_unused_fd_flags (O_CLOEXEC ); + err =get_unused_fd (O_CLOEXEC );if (err <0 )return err;
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -1
@@ -4104,7 +4104,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,DECLARE_VAL_CONTEXT (val_ctx, sw_context,1 );if (flags &DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); + out_fence_fd =get_unused_fd (O_CLOEXEC );if (out_fence_fd <0 ) {VMW_DEBUG_USER ("Failed to get a fence fd.\n" );return out_fence_fd;
drivers/hv/mshv_root_main.c +1 -1
@@ -1966,7 +1966,7 @@ mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)if (ret) goto remove_partition; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { ret = fd; goto remove_partition;
drivers/infiniband/core/rdma_core.c +1 -1
@@ -471,7 +471,7 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj, goto err_fd; } - new_fd =get_unused_fd_flags (O_CLOEXEC ); + new_fd =get_unused_fd (O_CLOEXEC );if (new_fd <0 ) { ret =ERR_PTR (new_fd); goto err_fd;
drivers/iommu/iommufd/eventq.c +1 -1
@@ -454,7 +454,7 @@ static int iommufd_eventq_init(struct iommufd_eventq *eventq, char *name, eventq->filep = filep;refcount_inc (&eventq->obj.users); - fdno =get_unused_fd_flags (O_CLOEXEC ); + fdno =get_unused_fd (O_CLOEXEC );if (fdno <0 )fput (filep);return fdno;
drivers/iommu/iommufd/selftest.c +1 -1
@@ -1366,7 +1366,7 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,if (IS_ERR (staccess))return PTR_ERR (staccess); - fdno =get_unused_fd_flags (O_CLOEXEC ); + fdno =get_unused_fd (O_CLOEXEC );if (fdno <0 ) { rc = -ENOMEM ; goto out_free_staccess;
drivers/media/mc/mc-request.c +1 -1
@@ -297,7 +297,7 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)if (!req)return -ENOMEM ; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { ret = fd; goto err_free_req;
drivers/misc/ntsync.c +1 -1
@@ -724,7 +724,7 @@ static int ntsync_obj_get_fd(struct ntsync_obj *obj)struct file *file;int fd; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd; file =anon_inode_getfile ("ntsync" , &ntsync_obj_fops, obj,O_RDWR );
drivers/tty/pty.c +1 -1
@@ -609,7 +609,7 @@ int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags)if (tty->driver != ptm_driver)return -EIO ; - fd =get_unused_fd_flags (flags); + fd =get_unused_fd (flags);if (fd <0 ) { retval = fd; goto err;
drivers/vfio/group.c +1 -1
@@ -314,7 +314,7 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,if (IS_ERR (device))return PTR_ERR (device); - fdno =get_unused_fd_flags (O_CLOEXEC ); + fdno =get_unused_fd (O_CLOEXEC );if (fdno <0 ) { ret = fdno; goto err_put_device;
drivers/vfio/vfio_main.c +1 -1
@@ -861,7 +861,7 @@ static int vfio_ioct_mig_return_fd(struct file *filp, void __user *arg,int ret;int fd; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { ret = fd; goto out_fput;
drivers/virt/nitro_enclaves/ne_misc_dev.c +1 -1
@@ -1651,7 +1651,7 @@ static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 __user *slot_ui goto free_cpumask; } - enclave_fd =get_unused_fd_flags (O_CLOEXEC ); + enclave_fd =get_unused_fd (O_CLOEXEC );if (enclave_fd <0 ) { rc = enclave_fd;
fs/anon_inodes.c +1 -1
@@ -226,7 +226,7 @@ static int __anon_inode_getfd(const char *name,int error, fd;struct file *file; - error =get_unused_fd_flags (flags); + error =get_unused_fd (flags);if (error <0 )return error; fd = error;
fs/autofs/dev-ioctl.c +1 -1
@@ -233,7 +233,7 @@ static int autofs_dev_ioctl_open_mountpoint(const char *name, dev_t devid) {int err, fd; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (likely (fd >=0 )) {struct file *filp;struct path path;
fs/bcachefs/thread_with_file.c +1 -1
@@ -43,7 +43,7 @@ int bch2_run_thread_with_file(struct thread_with_file *thr,if (ret)return ret; - ret =get_unused_fd_flags (fd_flags); + ret =get_unused_fd (fd_flags);if (ret <0 ) goto err; fd = ret;
fs/cachefiles/ondemand.c +1 -1
@@ -311,7 +311,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req,if (ret <0 ) goto err; - anon_file->fd =get_unused_fd_flags (O_WRONLY ); + anon_file->fd =get_unused_fd (O_WRONLY );if (anon_file->fd <0 ) { ret = anon_file->fd; goto err_free_id;
fs/eventfd.c +1 -1
@@ -402,7 +402,7 @@ static int do_eventfd(unsigned int count, int flags) flags &=EFD_SHARED_FCNTL_FLAGS ; flags |=O_RDWR ; - fd =get_unused_fd_flags (flags); + fd =get_unused_fd (flags);if (fd <0 ) goto err;
fs/eventpoll.c +1 -1
@@ -2234,7 +2234,7 @@ static int do_epoll_create(int flags)* Creates all the items needed to setup an eventpoll file. That is, * a file structure and a free file descriptor. */ - fd =get_unused_fd_flags (O_RDWR | (flags &O_CLOEXEC )); + fd =get_unused_fd (O_RDWR | (flags &O_CLOEXEC ));if (fd <0 ) { error = fd; goto out_free_ep;
fs/exec.c +1 -1
@@ -1388,7 +1388,7 @@ int begin_new_exec(struct linux_binprm * bprm)/* Pass the opened binary to the interpreter. */ if (bprm->have_execfd) { - retval =get_unused_fd_flags (0 ); + retval =get_unused_fd (0 );if (retval <0 ) goto out_unlock;fd_install (retval, bprm->executable);
fs/file.c +7 -7
@@ -597,16 +597,16 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)return error; } -int __get_unused_fd_flags (unsigned flags,unsigned long nofile) +int __get_unused_fd (unsigned flags,unsigned long nofile) {return alloc_fd (0 , nofile, flags); } -int get_unused_fd_flags (unsigned flags) +int get_unused_fd (unsigned flags) { -return __get_unused_fd_flags (flags,rlimit (RLIMIT_NOFILE )); +return __get_unused_fd (flags,rlimit (RLIMIT_NOFILE )); } -EXPORT_SYMBOL (get_unused_fd_flags); +EXPORT_SYMBOL (get_unused_fd);static void __put_unused_fd (struct files_struct *files,unsigned int fd) {
@@ -1257,7 +1257,7 @@ __releases(&files->file_lock)* not populate it yet. * * Broadly speaking we may be racing against the following: -* fd = get_unused_fd_flags(); // fd slot reserved, ->fd[fd] == NULL +* fd = get_unused_fd(); // fd slot reserved, ->fd[fd] == NULL * file = hard_work_goes_here(); * fd_install(fd, file); // only now ->fd[fd] == file *
@@ -1342,7 +1342,7 @@ int receive_fd(struct file *file, int __user *ufd, unsigned int o_flags)if (error)return error; - new_fd =get_unused_fd_flags (o_flags); + new_fd =get_unused_fd (o_flags);if (new_fd <0 )return new_fd;
@@ -1438,7 +1438,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)struct file *file =fget_raw (fildes);if (file) { - ret =get_unused_fd_flags (0 ); + ret =get_unused_fd (0 );if (ret >=0 )fd_install (ret, file);else
fs/init.c +1 -1
@@ -262,7 +262,7 @@ int __init init_dup(struct file *file) {int fd; - fd =get_unused_fd_flags (0 ); + fd =get_unused_fd (0 );if (fd <0 )return fd;fd_install (fd,get_file (file));
fs/namespace.c +3 -3
@@ -3195,7 +3195,7 @@ SYSCALL_DEFINE3(open_tree, int, dfd, const char __user *, filename, unsigned, flif (IS_ERR (file))return PTR_ERR (file); - fd =get_unused_fd_flags (flags &O_CLOEXEC ); + fd =get_unused_fd (flags &O_CLOEXEC );if (fd <0 )return fd;
@@ -4575,7 +4575,7 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, } file->f_mode |=FMODE_NEED_UNMOUNT ; - ret =get_unused_fd_flags ((flags &FSMOUNT_CLOEXEC ) ?O_CLOEXEC :0 ); + ret =get_unused_fd ((flags &FSMOUNT_CLOEXEC ) ?O_CLOEXEC :0 );if (ret >=0 )fd_install (ret, file);else
@@ -5293,7 +5293,7 @@ SYSCALL_DEFINE5(open_tree_attr, int, dfd, const char __user *, filename,finish_mount_kattr (&kattr); } - fd =get_unused_fd_flags (flags &O_CLOEXEC ); + fd =get_unused_fd (flags &O_CLOEXEC );if (fd <0 )return fd;
fs/notify/fanotify/fanotify_user.c +2 -2
@@ -259,7 +259,7 @@ static int create_fd(struct fsnotify_group *group, const struct path *path,int client_fd;struct file *new_file; - client_fd =get_unused_fd_flags (group->fanotify_data.f_flags); + client_fd =get_unused_fd (group->fanotify_data.f_flags);if (client_fd <0 )return client_fd;
@@ -1658,7 +1658,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) goto out_destroy_group; } - fd =get_unused_fd_flags (f_flags); + fd =get_unused_fd (f_flags);if (fd <0 ) goto out_destroy_group;
fs/open.c +1 -1
@@ -1424,7 +1424,7 @@ static int do_sys_openat2(int dfd, const char __user *filename,if (IS_ERR (tmp))return PTR_ERR (tmp); - fd =get_unused_fd_flags (how->flags); + fd =get_unused_fd (how->flags);if (likely (fd >=0 )) {struct file *f =do_filp_open (dfd, tmp, &op);if (IS_ERR (f)) {
fs/pipe.c +2 -2
@@ -985,12 +985,12 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags)if (error)return error; - error =get_unused_fd_flags (flags); + error =get_unused_fd (flags);if (error <0 ) goto err_read_pipe; fdr = error; - error =get_unused_fd_flags (flags); + error =get_unused_fd (flags);if (error <0 ) goto err_fdr; fdw = error;
fs/signalfd.c +1 -1
@@ -271,7 +271,7 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags) ctx->sigmask = *mask; - ufd =get_unused_fd_flags (flags &O_CLOEXEC ); + ufd =get_unused_fd (flags &O_CLOEXEC );if (ufd <0 ) {kfree (ctx);return ufd;
fs/timerfd.c +1 -1
@@ -432,7 +432,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) ctx->moffs =ktime_mono_to_real (0 ); - ufd =get_unused_fd_flags (flags &TFD_SHARED_FCNTL_FLAGS ); + ufd =get_unused_fd (flags &TFD_SHARED_FCNTL_FLAGS );if (ufd <0 ) {kfree (ctx);return ufd;
fs/userfaultfd.c +1 -1
@@ -2112,7 +2112,7 @@ static int new_userfaultfd(int flags)atomic_set (&ctx->mmap_changing,0 ); ctx->mm = current->mm; - fd =get_unused_fd_flags (flags &UFFD_SHARED_FCNTL_FLAGS ); + fd =get_unused_fd (flags &UFFD_SHARED_FCNTL_FLAGS );if (fd <0 ) goto err_out;
fs/xfs/xfs_handle.c +1 -1
@@ -279,7 +279,7 @@ xfs_open_by_handle( goto out_dput; } - fd =get_unused_fd_flags (0 ); + fd =get_unused_fd (0 );if (fd <0 ) { error = fd; goto out_dput;
include/linux/file.h +3 -3
@@ -88,12 +88,12 @@ extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);extern int replace_fd (unsigned fd,struct file *file,unsigned flags);extern void set_close_on_exec (unsigned int fd,int flag);extern bool get_close_on_exec (unsigned int fd); -extern int __get_unused_fd_flags (unsigned flags,unsigned long nofile); -extern int get_unused_fd_flags (unsigned flags); +extern int __get_unused_fd (unsigned flags,unsigned long nofile); +extern int get_unused_fd (unsigned flags);extern void put_unused_fd (unsigned int fd); DEFINE_CLASS(get_unused_fd, int, if (_T >= 0) put_unused_fd(_T), - get_unused_fd_flags(flags), unsigned flags) + get_unused_fd(flags), unsigned flags) DEFINE_FREE(fput, struct file *, if (!IS_ERR_OR_NULL(_T)) fput(_T))/*
include/uapi/linux/nitro_enclaves.h +1 -1
@@ -41,7 +41,7 @@* bookkeeping variables. * * NE_ERR_NO_CPUS_AVAIL_IN_POOL - No NE CPU pool set / no CPUs available * in the pool. -* * Error codes from get_unused_fd_flags() and anon_inode_getfile(). +* * Error codes from get_unused_fd() and anon_inode_getfile(). * * Error codes from the NE PCI device request. */ #define NE_CREATE_VM _IOR(0xAE, 0x20, __u64)
io_uring/io_uring.c +1 -1
@@ -3542,7 +3542,7 @@ static int io_uring_install_fd(struct file *file) {int fd; - fd =get_unused_fd_flags (O_RDWR |O_CLOEXEC ); + fd =get_unused_fd (O_RDWR |O_CLOEXEC );if (fd <0 )return fd;fd_install (fd, file);
io_uring/net.c +2 -2
@@ -1611,7 +1611,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags) retry:if (!fixed) { - fd =__get_unused_fd_flags (accept->flags, accept->nofile); + fd =__get_unused_fd (accept->flags, accept->nofile);if (unlikely (fd <0 ))return fd; }
@@ -1683,7 +1683,7 @@ int io_socket(struct io_kiocb *req, unsigned int issue_flags)int ret, fd;if (!fixed) { - fd =__get_unused_fd_flags (sock->flags, sock->nofile); + fd =__get_unused_fd (sock->flags, sock->nofile);if (unlikely (fd <0 ))return fd; }
io_uring/openclose.c +1 -1
@@ -132,7 +132,7 @@ int io_openat2(struct io_kiocb *req, unsigned int issue_flags) }if (!fixed) { - ret =__get_unused_fd_flags (open->how.flags, open->nofile); + ret =__get_unused_fd (open->how.flags, open->nofile);if (ret <0 ) goto err; }
ipc/mqueue.c +1 -1
@@ -907,7 +907,7 @@ static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,if (IS_ERR (name))return PTR_ERR (name); - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) goto out_putname;
kernel/bpf/bpf_iter.c +1 -1
@@ -642,7 +642,7 @@ int bpf_iter_new_fd(struct bpf_link *link)return -EINVAL ; flags =O_RDONLY |O_CLOEXEC ; - fd =get_unused_fd_flags (flags); + fd =get_unused_fd (flags);if (fd <0 )return fd;
kernel/bpf/syscall.c +1 -1
@@ -3304,7 +3304,7 @@ int bpf_link_prime(struct bpf_link *link, struct bpf_link_primer *primer)struct file *file;int fd, id; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
kernel/bpf/token.c +1 -1
@@ -192,7 +192,7 @@ int bpf_token_create(union bpf_attr *attr)if (err) goto out_token; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { err = fd; goto out_token;
kernel/events/core.c +1 -1
@@ -13154,7 +13154,7 @@ SYSCALL_DEFINE5(perf_event_open,if (flags &PERF_FLAG_FD_CLOEXEC ) f_flags |=O_CLOEXEC ; - event_fd =get_unused_fd_flags (f_flags); + event_fd =get_unused_fd (f_flags);if (event_fd <0 )return event_fd;
kernel/seccomp.c +1 -1
@@ -1976,7 +1976,7 @@ static long seccomp_set_mode_filter(unsigned int flags,return PTR_ERR (prepared);if (flags &SECCOMP_FILTER_FLAG_NEW_LISTENER ) { - listener =get_unused_fd_flags (O_CLOEXEC ); + listener =get_unused_fd (O_CLOEXEC );if (listener <0 ) { ret = listener; goto out_free;
mm/memfd.c +1 -1
@@ -471,7 +471,7 @@ SYSCALL_DEFINE2(memfd_create,if (IS_ERR (name))return PTR_ERR (name); - fd =get_unused_fd_flags ((flags &MFD_CLOEXEC ) ?O_CLOEXEC :0 ); + fd =get_unused_fd ((flags &MFD_CLOEXEC ) ?O_CLOEXEC :0 );if (fd <0 ) { error = fd; goto err_name;
mm/secretmem.c +1 -1
@@ -245,7 +245,7 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)if (atomic_read (&secretmem_users) <0 )return -ENFILE ; - fd =get_unused_fd_flags (flags &O_CLOEXEC ); + fd =get_unused_fd (flags &O_CLOEXEC );if (fd <0 )return fd;
net/handshake/netlink.c +1 -1
@@ -110,7 +110,7 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info) goto out_status; sock = req->hr_sk->sk_socket; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { err = fd; goto out_complete;
net/kcm/kcmsock.c +1 -1
@@ -1557,7 +1557,7 @@ static int kcm_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)struct kcm_clone info;struct file *file; - info.fd =get_unused_fd_flags (0 ); + info.fd =get_unused_fd (0 );if (unlikely (info.fd <0 ))return info.fd;
net/sctp/socket.c +1 -1
@@ -5687,7 +5687,7 @@ static int sctp_getsockopt_peeloff_common(struct sock *sk, sctp_peeloff_arg_t *p goto out;/* Map the socket to an unused fd that can be returned to the user. */ - retval =get_unused_fd_flags (flags &SOCK_CLOEXEC ); + retval =get_unused_fd (flags &SOCK_CLOEXEC );if (retval <0 ) {sock_release (newsock); goto out;
net/socket.c +4 -4
@@ -491,7 +491,7 @@ EXPORT_SYMBOL(sock_alloc_file);static int sock_map_fd (struct socket *sock,int flags) {struct file *newfile; -int fd =get_unused_fd_flags (flags); +int fd =get_unused_fd (flags);if (unlikely (fd <0 )) {sock_release (sock);return fd;
@@ -1720,11 +1720,11 @@ int __sys_socketpair(int family, int type, int protocol, int __user *usockvec)* reserve descriptors and make sure we won't fail * to return them to userland. */ - fd1 =get_unused_fd_flags (flags); + fd1 =get_unused_fd (flags);if (unlikely (fd1 <0 ))return fd1; - fd2 =get_unused_fd_flags (flags); + fd2 =get_unused_fd (flags);if (unlikely (fd2 <0 )) {put_unused_fd (fd1);return fd2;
@@ -1957,7 +1957,7 @@ static int __sys_accept4_file(struct file *file, struct sockaddr __user *upeer_sif (SOCK_NONBLOCK !=O_NONBLOCK && (flags &SOCK_NONBLOCK )) flags = (flags & ~SOCK_NONBLOCK ) |O_NONBLOCK ; - newfd =get_unused_fd_flags (flags); + newfd =get_unused_fd (flags);if (unlikely (newfd <0 ))return newfd;
net/unix/af_unix.c +1 -1
@@ -3110,7 +3110,7 @@ static int unix_open_file(struct sock *sk)path_get (&path); - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) goto out;
rust/kernel/fs/file.rs +5 -5
@@ -384,7 +384,7 @@ pub struct FileDescriptorReservation {/// Prevent values of this type from being moved to a different task. /// /// The `fd_install` and `put_unused_fd` functions assume that the value of `current` is -/// unchanged since the call to `get_unused_fd_flags`. By adding this marker to this type, we +/// unchanged since the call to `get_unused_fd`. By adding this marker to this type, we /// prevent it from being moved across task boundaries, which ensures that `current` does not /// change while this value exists. _not_send: NotThreadSafe,
@@ -393,9 +393,9 @@ pub struct FileDescriptorReservation {impl FileDescriptorReservation {/// Creates a new file descriptor reservation. #[inline] -pub fn get_unused_fd_flags (flags:u32 ) ->Result <Self > { +pub fn get_unused_fd (flags:u32 ) ->Result <Self > {// SAFETY: FFI call, there are no safety requirements on `flags`. -let fd:i32 =unsafe { bindings::get_unused_fd_flags (flags) }; +let fd:i32 =unsafe { bindings::get_unused_fd (flags) };if fd <0 {return Err (Error ::from_errno (fd)); }
@@ -417,7 +417,7 @@ pub fn reserved_fd(&self) -> u32 {/// [`FileDescriptorReservation`], so it will not be usable after this call. #[inline] pub fn fd_install (self, file:ARef <File >) { -// SAFETY: `self.fd` was previously returned by `get_unused_fd_flags`. We have not yet used +// SAFETY: `self.fd` was previously returned by `get_unused_fd`. We have not yet used // the fd, so it is still valid, and `current` still refers to the same task, as this type // cannot be moved across task boundaries. //
@@ -439,7 +439,7 @@ impl Drop for FileDescriptorReservation {#[inline] fn drop (&mut self) {// SAFETY: By the type invariants of this type, `self.fd` was previously returned by -// `get_unused_fd_flags`. We have not yet used the fd, so it is still valid, and `current` +// `get_unused_fd`. We have not yet used the fd, so it is still valid, and `current` // still refers to the same task, as this type cannot be moved across task boundaries. unsafe { bindings::put_unused_fd (self.fd) }; }
sound/core/compress_offload.c +2 -2
@@ -1045,10 +1045,10 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_ retval = -EINVAL ; goto cleanup; } - fd_i =get_unused_fd_flags (O_WRONLY |O_CLOEXEC ); + fd_i =get_unused_fd (O_WRONLY |O_CLOEXEC );if (fd_i <0 ) goto cleanup; - fd_o =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); + fd_o =get_unused_fd (O_RDONLY |O_CLOEXEC );if (fd_o <0 ) {put_unused_fd (fd_i); goto cleanup;
virt/kvm/guest_memfd.c +1 -1
@@ -410,7 +410,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)struct file *file;int fd, err; - fd =get_unused_fd_flags (0 ); + fd =get_unused_fd (0 );if (fd <0 )return fd;
virt/kvm/kvm_main.c +3 -3
@@ -4236,7 +4236,7 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)snprintf (name,sizeof (name),"kvm-vcpu-stats:%d" , vcpu->vcpu_id); - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
@@ -5031,7 +5031,7 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)int fd;struct file *file; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
@@ -5395,7 +5395,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)struct kvm *kvm;struct file *file; - fd =get_unused_fd_flags (O_CLOEXEC ); + fd =get_unused_fd (O_CLOEXEC );if (fd <0 )return fd;
base-commit: 06a22366d6a11ca8ed03c738171822ac9b714cfd
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Carlos Llamas
maintainerQuoted 3 lines · Anish Moorthy
The current name can be misread as having something to do with unused *flags*. And without a
get_unused_fd()function already floating around, it's easy to resolve this by dropping the suffix.
I don't understand the "unused flags" argument. Did you interpret the current naming as "get the flags not used by a certain fd"?
Note there _used_ to be a get_unused_fd() that would take no arguments and thus the naming behind this _flags() version (just FYI).
Quoted 3 lines
I'm not sure if there's any appetite for refactors like this: they're tedious for sure. I couldn't find any discouragement in the docs though, so I figured I'd just post the patch and let it find me.
If it helps, this kind of patches are usually tagged as "treewide:" and are often implemented using coccinelle scripts.
Also, for this patch in particular I would:
Cc: Al Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
drivers/android/binder.c static int binder_apply_fd_fixups(struct binder_proc *proc, · line 4624
Quoted 13 lines
drivers/android/binder.c +1
-1@@ -4618,7 +4618,7 @@ static int binder_apply_fd_fixups(struct binder_proc *proc,int ret =0 ;list_for_each_entry (fixup, &t->fd_fixups, fixup_entry) { -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { binder_debug(BINDER_DEBUG_TRANSACTION,
This is the only reason I found this patch (binder), and fwiw the renaming looks OK to me.
Cheers,
Carlos Llamas
Quoted 3 lines · Carlos Llamas
I don't understand the "unused flags" argument. Did you interpret the current naming as "get the flags not used by a certain fd"?
Right
Quoted 2 lines
If it helps, this kind of patches are usually tagged as "treewide:" and are often implemented using coccinelle scripts.
Oh neat, I had no idea about conccinelle: thanks for cluing me in
Quoted 23 lines
Also, for this patch in particular I would:
Cc: Al Viro <[email protected]>
Cc: Christian Brauner <[email protected]>drivers/android/binder.c static int binder_apply_fd_fixups(struct binder_proc *proc, · line 4624
Quoted 13 lines
drivers/android/binder.c +1
-1@@ -4618,7 +4618,7 @@ static int binder_apply_fd_fixups(struct binder_proc *proc,int ret =0 ;list_for_each_entry (fixup, &t->fd_fixups, fixup_entry) { -int fd =get_unused_fd_flags (O_CLOEXEC ); +int fd =get_unused_fd (O_CLOEXEC );if (fd <0 ) { binder_debug(BINDER_DEBUG_TRANSACTION,This is the only reason I found this patch (binder), and fwiw the renaming looks OK to me.
Cheers,
Carlos Llamas