Skip to content

Commit f8ffbc3

Browse files
committed
Merge tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull 'struct fd' updates from Al Viro: "Just the 'struct fd' layout change, with conversion to accessor helpers" * tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: add struct fd constructors, get rid of __to_fd() struct fd: representation change introduce fd_file(), convert all accessors to it.
2 parents f8eb5bd + de12c33 commit f8ffbc3

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

+562
-559
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
@@ -903,10 +903,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
903903
{
904904
struct fd f = fdget(attribute_fd);
905905

906-
if (!f.file)
906+
if (!fd_file(f))
907907
return -EINVAL;
908908

909-
if (f.file->f_op != &sgx_provision_fops) {
909+
if (fd_file(f)->f_op != &sgx_provision_fops) {
910910
fdput(f);
911911
return -EINVAL;
912912
}

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;
@@ -2803,15 +2803,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
28032803
struct kvm_sev_info *source_sev, *mirror_sev;
28042804
int ret;
28052805

2806-
if (!f.file)
2806+
if (!fd_file(f))
28072807
return -EBADF;
28082808

2809-
if (!file_is_kvm(f.file)) {
2809+
if (!file_is_kvm(fd_file(f))) {
28102810
ret = -EBADF;
28112811
goto e_source_fput;
28122812
}
28132813

2814-
source_kvm = f.file->private_data;
2814+
source_kvm = fd_file(f)->private_data;
28152815
ret = sev_lock_two_vms(kvm, source_kvm);
28162816
if (ret)
28172817
goto e_source_fput;

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

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

45-
if (!f.file)
45+
if (!fd_file(f))
4646
return -EINVAL;
4747

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

74-
if (!f.file)
74+
if (!fd_file(f))
7575
return -EINVAL;
7676

77-
r = amdgpu_file_to_fpriv(f.file, &fpriv);
77+
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
7878
if (r) {
7979
fdput(f);
8080
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

+5-5
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
572572
struct inode *inode = NULL;
573573
int new_xrcd = 0;
574574
struct ib_device *ib_dev;
575-
struct fd f = {};
575+
struct fd f = EMPTY_FD;
576576
int ret;
577577

578578
ret = uverbs_request(attrs, &cmd, sizeof(cmd));
@@ -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)