Skip to content

Commit 1da91ea

Browse files
author
Al Viro
committed
introduce fd_file(), convert all accessors to it.
For any changes of struct fd representation we need to turn existing accesses to fields into calls of wrappers. Accesses to struct fd::flags are very few (3 in linux/file.h, 1 in net/socket.c, 3 in fs/overlayfs/file.c and 3 more in explicit initializers). Those can be dealt with in the commit converting to new layout; accesses to struct fd::file are too many for that. This commit converts (almost) all of f.file to fd_file(f). It's not entirely mechanical ('file' is used as a member name more than just in struct fd) and it does not even attempt to distinguish the uses in pointer context from those in boolean context; the latter will be eventually turned into a separate helper (fd_empty()). NOTE: mass conversion to fd_empty(), tempting as it might be, is a bad idea; better do that piecewise in commit that convert from fdget...() to CLASS(...). [conflicts in fs/fhandle.c, kernel/bpf/syscall.c, mm/memcontrol.c caught by git; fs/stat.c one got caught by git grep] [fs/xattr.c conflict] Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 8400291 commit 1da91ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+504
-502
lines changed

arch/alpha/kernel/osf_sys.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
160160
.count = count
161161
};
162162

163-
if (!arg.file)
163+
if (!fd_file(arg))
164164
return -EBADF;
165165

166-
error = iterate_dir(arg.file, &buf.ctx);
166+
error = iterate_dir(fd_file(arg), &buf.ctx);
167167
if (error >= 0)
168168
error = buf.error;
169169
if (count != buf.count)

arch/arm/kernel/sys_oabi-compat.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -239,33 +239,33 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
239239
struct flock64 flock;
240240
long err = -EBADF;
241241

242-
if (!f.file)
242+
if (!fd_file(f))
243243
goto out;
244244

245245
switch (cmd) {
246246
case F_GETLK64:
247247
case F_OFD_GETLK:
248-
err = security_file_fcntl(f.file, cmd, arg);
248+
err = security_file_fcntl(fd_file(f), cmd, arg);
249249
if (err)
250250
break;
251251
err = get_oabi_flock(&flock, argp);
252252
if (err)
253253
break;
254-
err = fcntl_getlk64(f.file, cmd, &flock);
254+
err = fcntl_getlk64(fd_file(f), cmd, &flock);
255255
if (!err)
256256
err = put_oabi_flock(&flock, argp);
257257
break;
258258
case F_SETLK64:
259259
case F_SETLKW64:
260260
case F_OFD_SETLK:
261261
case F_OFD_SETLKW:
262-
err = security_file_fcntl(f.file, cmd, arg);
262+
err = security_file_fcntl(fd_file(f), cmd, arg);
263263
if (err)
264264
break;
265265
err = get_oabi_flock(&flock, argp);
266266
if (err)
267267
break;
268-
err = fcntl_setlk64(fd, f.file, cmd, &flock);
268+
err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
269269
break;
270270
default:
271271
err = sys_fcntl64(fd, cmd, arg);

arch/powerpc/kvm/book3s_64_vio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
118118
struct fd f;
119119

120120
f = fdget(tablefd);
121-
if (!f.file)
121+
if (!fd_file(f))
122122
return -EBADF;
123123

124124
rcu_read_lock();
125125
list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
126-
if (stt == f.file->private_data) {
126+
if (stt == fd_file(f)->private_data) {
127127
found = true;
128128
break;
129129
}

arch/powerpc/kvm/powerpc.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1938,11 +1938,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19381938

19391939
r = -EBADF;
19401940
f = fdget(cap->args[0]);
1941-
if (!f.file)
1941+
if (!fd_file(f))
19421942
break;
19431943

19441944
r = -EPERM;
1945-
dev = kvm_device_from_filp(f.file);
1945+
dev = kvm_device_from_filp(fd_file(f));
19461946
if (dev)
19471947
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
19481948

@@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19571957

19581958
r = -EBADF;
19591959
f = fdget(cap->args[0]);
1960-
if (!f.file)
1960+
if (!fd_file(f))
19611961
break;
19621962

19631963
r = -EPERM;
1964-
dev = kvm_device_from_filp(f.file);
1964+
dev = kvm_device_from_filp(fd_file(f));
19651965
if (dev) {
19661966
if (xics_on_xive())
19671967
r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
@@ -1980,7 +1980,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19801980

19811981
r = -EBADF;
19821982
f = fdget(cap->args[0]);
1983-
if (!f.file)
1983+
if (!fd_file(f))
19841984
break;
19851985

19861986
r = -ENXIO;
@@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19901990
}
19911991

19921992
r = -EPERM;
1993-
dev = kvm_device_from_filp(f.file);
1993+
dev = kvm_device_from_filp(fd_file(f));
19941994
if (dev)
19951995
r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
19961996
cap->args[1]);

arch/powerpc/platforms/cell/spu_syscalls.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
6666
if (flags & SPU_CREATE_AFFINITY_SPU) {
6767
struct fd neighbor = fdget(neighbor_fd);
6868
ret = -EBADF;
69-
if (neighbor.file) {
70-
ret = calls->create_thread(name, flags, mode, neighbor.file);
69+
if (fd_file(neighbor)) {
70+
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
7171
fdput(neighbor);
7272
}
7373
} else
@@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
8989

9090
ret = -EBADF;
9191
arg = fdget(fd);
92-
if (arg.file) {
93-
ret = calls->spu_run(arg.file, unpc, ustatus);
92+
if (fd_file(arg)) {
93+
ret = calls->spu_run(fd_file(arg), unpc, ustatus);
9494
fdput(arg);
9595
}
9696

arch/x86/kernel/cpu/sgx/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
895895
{
896896
struct fd f = fdget(attribute_fd);
897897

898-
if (!f.file)
898+
if (!fd_file(f))
899899
return -EINVAL;
900900

901-
if (f.file->f_op != &sgx_provision_fops) {
901+
if (fd_file(f)->f_op != &sgx_provision_fops) {
902902
fdput(f);
903903
return -EINVAL;
904904
}

arch/x86/kvm/svm/sev.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ static int __sev_issue_cmd(int fd, int id, void *data, int *error)
534534
int ret;
535535

536536
f = fdget(fd);
537-
if (!f.file)
537+
if (!fd_file(f))
538538
return -EBADF;
539539

540-
ret = sev_issue_cmd_external_user(f.file, id, data, error);
540+
ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
541541

542542
fdput(f);
543543
return ret;
@@ -2078,15 +2078,15 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
20782078
bool charged = false;
20792079
int ret;
20802080

2081-
if (!f.file)
2081+
if (!fd_file(f))
20822082
return -EBADF;
20832083

2084-
if (!file_is_kvm(f.file)) {
2084+
if (!file_is_kvm(fd_file(f))) {
20852085
ret = -EBADF;
20862086
goto out_fput;
20872087
}
20882088

2089-
source_kvm = f.file->private_data;
2089+
source_kvm = fd_file(f)->private_data;
20902090
ret = sev_lock_two_vms(kvm, source_kvm);
20912091
if (ret)
20922092
goto out_fput;
@@ -2801,15 +2801,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
28012801
struct kvm_sev_info *source_sev, *mirror_sev;
28022802
int ret;
28032803

2804-
if (!f.file)
2804+
if (!fd_file(f))
28052805
return -EBADF;
28062806

2807-
if (!file_is_kvm(f.file)) {
2807+
if (!file_is_kvm(fd_file(f))) {
28082808
ret = -EBADF;
28092809
goto e_source_fput;
28102810
}
28112811

2812-
source_kvm = f.file->private_data;
2812+
source_kvm = fd_file(f)->private_data;
28132813
ret = sev_lock_two_vms(kvm, source_kvm);
28142814
if (ret)
28152815
goto e_source_fput;

drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
4343
uint32_t id;
4444
int r;
4545

46-
if (!f.file)
46+
if (!fd_file(f))
4747
return -EINVAL;
4848

49-
r = amdgpu_file_to_fpriv(f.file, &fpriv);
49+
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
5050
if (r) {
5151
fdput(f);
5252
return r;
@@ -72,10 +72,10 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
7272
struct amdgpu_ctx *ctx;
7373
int r;
7474

75-
if (!f.file)
75+
if (!fd_file(f))
7676
return -EINVAL;
7777

78-
r = amdgpu_file_to_fpriv(f.file, &fpriv);
78+
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
7979
if (r) {
8080
fdput(f);
8181
return r;

drivers/gpu/drm/drm_syncobj.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,16 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
715715
struct fd f = fdget(fd);
716716
int ret;
717717

718-
if (!f.file)
718+
if (!fd_file(f))
719719
return -EINVAL;
720720

721-
if (f.file->f_op != &drm_syncobj_file_fops) {
721+
if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
722722
fdput(f);
723723
return -EINVAL;
724724
}
725725

726726
/* take a reference to put in the idr */
727-
syncobj = f.file->private_data;
727+
syncobj = fd_file(f)->private_data;
728728
drm_syncobj_get(syncobj);
729729

730730
idr_preload(GFP_KERNEL);

drivers/infiniband/core/ucma.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1624,13 +1624,13 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
16241624

16251625
/* Get current fd to protect against it being closed */
16261626
f = fdget(cmd.fd);
1627-
if (!f.file)
1627+
if (!fd_file(f))
16281628
return -ENOENT;
1629-
if (f.file->f_op != &ucma_fops) {
1629+
if (fd_file(f)->f_op != &ucma_fops) {
16301630
ret = -EINVAL;
16311631
goto file_put;
16321632
}
1633-
cur_file = f.file->private_data;
1633+
cur_file = fd_file(f)->private_data;
16341634

16351635
/* Validate current fd and prevent destruction of id. */
16361636
ctx = ucma_get_ctx(cur_file, cmd.id);

drivers/infiniband/core/uverbs_cmd.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
584584
if (cmd.fd != -1) {
585585
/* search for file descriptor */
586586
f = fdget(cmd.fd);
587-
if (!f.file) {
587+
if (!fd_file(f)) {
588588
ret = -EBADF;
589589
goto err_tree_mutex_unlock;
590590
}
591591

592-
inode = file_inode(f.file);
592+
inode = file_inode(fd_file(f));
593593
xrcd = find_xrcd(ibudev, inode);
594594
if (!xrcd && !(cmd.oflags & O_CREAT)) {
595595
/* no file descriptor. Need CREATE flag */
@@ -632,7 +632,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
632632
atomic_inc(&xrcd->usecnt);
633633
}
634634

635-
if (f.file)
635+
if (fd_file(f))
636636
fdput(f);
637637

638638
mutex_unlock(&ibudev->xrcd_tree_mutex);
@@ -648,7 +648,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
648648
uobj_alloc_abort(&obj->uobject, attrs);
649649

650650
err_tree_mutex_unlock:
651-
if (f.file)
651+
if (fd_file(f))
652652
fdput(f);
653653

654654
mutex_unlock(&ibudev->xrcd_tree_mutex);

drivers/media/mc/mc-request.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ media_request_get_by_fd(struct media_device *mdev, int request_fd)
254254
return ERR_PTR(-EBADR);
255255

256256
f = fdget(request_fd);
257-
if (!f.file)
257+
if (!fd_file(f))
258258
goto err_no_req_fd;
259259

260-
if (f.file->f_op != &request_fops)
260+
if (fd_file(f)->f_op != &request_fops)
261261
goto err_fput;
262-
req = f.file->private_data;
262+
req = fd_file(f)->private_data;
263263
if (req->mdev != mdev)
264264
goto err_fput;
265265

drivers/media/rc/lirc_dev.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -820,20 +820,20 @@ struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
820820
struct lirc_fh *fh;
821821
struct rc_dev *dev;
822822

823-
if (!f.file)
823+
if (!fd_file(f))
824824
return ERR_PTR(-EBADF);
825825

826-
if (f.file->f_op != &lirc_fops) {
826+
if (fd_file(f)->f_op != &lirc_fops) {
827827
fdput(f);
828828
return ERR_PTR(-EINVAL);
829829
}
830830

831-
if (write && !(f.file->f_mode & FMODE_WRITE)) {
831+
if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
832832
fdput(f);
833833
return ERR_PTR(-EPERM);
834834
}
835835

836-
fh = f.file->private_data;
836+
fh = fd_file(f)->private_data;
837837
dev = fh->rc;
838838

839839
get_device(&dev->dev);

drivers/vfio/group.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
112112
return -EFAULT;
113113

114114
f = fdget(fd);
115-
if (!f.file)
115+
if (!fd_file(f))
116116
return -EBADF;
117117

118118
mutex_lock(&group->group_lock);
@@ -125,13 +125,13 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
125125
goto out_unlock;
126126
}
127127

128-
container = vfio_container_from_file(f.file);
128+
container = vfio_container_from_file(fd_file(f));
129129
if (container) {
130130
ret = vfio_container_attach_group(container, group);
131131
goto out_unlock;
132132
}
133133

134-
iommufd = iommufd_ctx_from_file(f.file);
134+
iommufd = iommufd_ctx_from_file(fd_file(f));
135135
if (!IS_ERR(iommufd)) {
136136
if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
137137
group->type == VFIO_NO_IOMMU)

drivers/vfio/virqfd.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ int vfio_virqfd_enable(void *opaque,
134134
INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
135135

136136
irqfd = fdget(fd);
137-
if (!irqfd.file) {
137+
if (!fd_file(irqfd)) {
138138
ret = -EBADF;
139139
goto err_fd;
140140
}
141141

142-
ctx = eventfd_ctx_fileget(irqfd.file);
142+
ctx = eventfd_ctx_fileget(fd_file(irqfd));
143143
if (IS_ERR(ctx)) {
144144
ret = PTR_ERR(ctx);
145145
goto err_ctx;
@@ -171,7 +171,7 @@ int vfio_virqfd_enable(void *opaque,
171171
init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
172172
init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
173173

174-
events = vfs_poll(irqfd.file, &virqfd->pt);
174+
events = vfs_poll(fd_file(irqfd), &virqfd->pt);
175175

176176
/*
177177
* Check if there was an event already pending on the eventfd

0 commit comments

Comments
 (0)