Skip to content

Commit 6348be0

Browse files
author
Al Viro
committed
fdget(), trivial conversions
fdget() is the first thing done in scope, all matching fdput() are immediately followed by leaving the scope. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 46b5e18 commit 6348be0

File tree

31 files changed

+164
-339
lines changed

31 files changed

+164
-339
lines changed

arch/powerpc/kvm/book3s_64_vio.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
115115
struct iommu_table_group *table_group;
116116
long i;
117117
struct kvmppc_spapr_tce_iommu_table *stit;
118-
struct fd f;
118+
CLASS(fd, f)(tablefd);
119119

120-
f = fdget(tablefd);
121-
if (!fd_file(f))
120+
if (fd_empty(f))
122121
return -EBADF;
123122

124123
rcu_read_lock();
@@ -130,16 +129,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
130129
}
131130
rcu_read_unlock();
132131

133-
if (!found) {
134-
fdput(f);
132+
if (!found)
135133
return -EINVAL;
136-
}
137134

138135
table_group = iommu_group_get_iommudata(grp);
139-
if (WARN_ON(!table_group)) {
140-
fdput(f);
136+
if (WARN_ON(!table_group))
141137
return -EFAULT;
142-
}
143138

144139
for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
145140
struct iommu_table *tbltmp = table_group->tables[i];
@@ -160,10 +155,8 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
160155
break;
161156
}
162157
}
163-
if (!tbl) {
164-
fdput(f);
158+
if (!tbl)
165159
return -EINVAL;
166-
}
167160

168161
rcu_read_lock();
169162
list_for_each_entry_rcu(stit, &stt->iommu_tables, next) {
@@ -174,23 +167,20 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
174167
/* stit is being destroyed */
175168
iommu_tce_table_put(tbl);
176169
rcu_read_unlock();
177-
fdput(f);
178170
return -ENOTTY;
179171
}
180172
/*
181173
* The table is already known to this KVM, we just increased
182174
* its KVM reference counter and can return.
183175
*/
184176
rcu_read_unlock();
185-
fdput(f);
186177
return 0;
187178
}
188179
rcu_read_unlock();
189180

190181
stit = kzalloc(sizeof(*stit), GFP_KERNEL);
191182
if (!stit) {
192183
iommu_tce_table_put(tbl);
193-
fdput(f);
194184
return -ENOMEM;
195185
}
196186

@@ -199,7 +189,6 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
199189

200190
list_add_rcu(&stit->next, &stt->iommu_tables);
201191

202-
fdput(f);
203192
return 0;
204193
}
205194

arch/powerpc/kvm/powerpc.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,31 +1933,28 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19331933
#endif
19341934
#ifdef CONFIG_KVM_MPIC
19351935
case KVM_CAP_IRQ_MPIC: {
1936-
struct fd f;
1936+
CLASS(fd, f)(cap->args[0]);
19371937
struct kvm_device *dev;
19381938

19391939
r = -EBADF;
1940-
f = fdget(cap->args[0]);
1941-
if (!fd_file(f))
1940+
if (fd_empty(f))
19421941
break;
19431942

19441943
r = -EPERM;
19451944
dev = kvm_device_from_filp(fd_file(f));
19461945
if (dev)
19471946
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
19481947

1949-
fdput(f);
19501948
break;
19511949
}
19521950
#endif
19531951
#ifdef CONFIG_KVM_XICS
19541952
case KVM_CAP_IRQ_XICS: {
1955-
struct fd f;
1953+
CLASS(fd, f)(cap->args[0]);
19561954
struct kvm_device *dev;
19571955

19581956
r = -EBADF;
1959-
f = fdget(cap->args[0]);
1960-
if (!fd_file(f))
1957+
if (fd_empty(f))
19611958
break;
19621959

19631960
r = -EPERM;
@@ -1968,34 +1965,27 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
19681965
else
19691966
r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
19701967
}
1971-
1972-
fdput(f);
19731968
break;
19741969
}
19751970
#endif /* CONFIG_KVM_XICS */
19761971
#ifdef CONFIG_KVM_XIVE
19771972
case KVM_CAP_PPC_IRQ_XIVE: {
1978-
struct fd f;
1973+
CLASS(fd, f)(cap->args[0]);
19791974
struct kvm_device *dev;
19801975

19811976
r = -EBADF;
1982-
f = fdget(cap->args[0]);
1983-
if (!fd_file(f))
1977+
if (fd_empty(f))
19841978
break;
19851979

19861980
r = -ENXIO;
1987-
if (!xive_enabled()) {
1988-
fdput(f);
1981+
if (!xive_enabled())
19891982
break;
1990-
}
19911983

19921984
r = -EPERM;
19931985
dev = kvm_device_from_filp(fd_file(f));
19941986
if (dev)
19951987
r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
19961988
cap->args[1]);
1997-
1998-
fdput(f);
19991989
break;
20001990
}
20011991
#endif /* CONFIG_KVM_XIVE */

arch/powerpc/platforms/cell/spu_syscalls.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
6464
return -ENOSYS;
6565

6666
if (flags & SPU_CREATE_AFFINITY_SPU) {
67-
struct fd neighbor = fdget(neighbor_fd);
67+
CLASS(fd, neighbor)(neighbor_fd);
6868
ret = -EBADF;
69-
if (fd_file(neighbor)) {
69+
if (!fd_empty(neighbor))
7070
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
71-
fdput(neighbor);
72-
}
7371
} else
7472
ret = calls->create_thread(name, flags, mode, NULL);
7573

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,19 +901,15 @@ static struct miscdevice sgx_dev_provision = {
901901
int sgx_set_attribute(unsigned long *allowed_attributes,
902902
unsigned int attribute_fd)
903903
{
904-
struct fd f = fdget(attribute_fd);
904+
CLASS(fd, f)(attribute_fd);
905905

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

909-
if (fd_file(f)->f_op != &sgx_provision_fops) {
910-
fdput(f);
909+
if (fd_file(f)->f_op != &sgx_provision_fops)
911910
return -EINVAL;
912-
}
913911

914912
*allowed_attributes |= SGX_ATTR_PROVISIONKEY;
915-
916-
fdput(f);
917913
return 0;
918914
}
919915
EXPORT_SYMBOL_GPL(sgx_set_attribute);

arch/x86/kvm/svm/sev.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,12 @@ static int sev_bind_asid(struct kvm *kvm, unsigned int handle, int *error)
530530

531531
static int __sev_issue_cmd(int fd, int id, void *data, int *error)
532532
{
533-
struct fd f;
534-
int ret;
533+
CLASS(fd, f)(fd);
535534

536-
f = fdget(fd);
537-
if (!fd_file(f))
535+
if (fd_empty(f))
538536
return -EBADF;
539537

540-
ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
541-
542-
fdput(f);
543-
return ret;
538+
return sev_issue_cmd_external_user(fd_file(f), id, data, error);
544539
}
545540

546541
static int sev_issue_cmd(struct kvm *kvm, int id, void *data, int *error)
@@ -2073,23 +2068,21 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
20732068
{
20742069
struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
20752070
struct kvm_sev_info *src_sev, *cg_cleanup_sev;
2076-
struct fd f = fdget(source_fd);
2071+
CLASS(fd, f)(source_fd);
20772072
struct kvm *source_kvm;
20782073
bool charged = false;
20792074
int ret;
20802075

2081-
if (!fd_file(f))
2076+
if (fd_empty(f))
20822077
return -EBADF;
20832078

2084-
if (!file_is_kvm(fd_file(f))) {
2085-
ret = -EBADF;
2086-
goto out_fput;
2087-
}
2079+
if (!file_is_kvm(fd_file(f)))
2080+
return -EBADF;
20882081

20892082
source_kvm = fd_file(f)->private_data;
20902083
ret = sev_lock_two_vms(kvm, source_kvm);
20912084
if (ret)
2092-
goto out_fput;
2085+
return ret;
20932086

20942087
if (kvm->arch.vm_type != source_kvm->arch.vm_type ||
20952088
sev_guest(kvm) || !sev_guest(source_kvm)) {
@@ -2136,8 +2129,6 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
21362129
cg_cleanup_sev->misc_cg = NULL;
21372130
out_unlock:
21382131
sev_unlock_two_vms(kvm, source_kvm);
2139-
out_fput:
2140-
fdput(f);
21412132
return ret;
21422133
}
21432134

@@ -2798,23 +2789,21 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,
27982789

27992790
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
28002791
{
2801-
struct fd f = fdget(source_fd);
2792+
CLASS(fd, f)(source_fd);
28022793
struct kvm *source_kvm;
28032794
struct kvm_sev_info *source_sev, *mirror_sev;
28042795
int ret;
28052796

2806-
if (!fd_file(f))
2797+
if (fd_empty(f))
28072798
return -EBADF;
28082799

2809-
if (!file_is_kvm(fd_file(f))) {
2810-
ret = -EBADF;
2811-
goto e_source_fput;
2812-
}
2800+
if (!file_is_kvm(fd_file(f)))
2801+
return -EBADF;
28132802

28142803
source_kvm = fd_file(f)->private_data;
28152804
ret = sev_lock_two_vms(kvm, source_kvm);
28162805
if (ret)
2817-
goto e_source_fput;
2806+
return ret;
28182807

28192808
/*
28202809
* Mirrors of mirrors should work, but let's not get silly. Also
@@ -2857,8 +2846,6 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
28572846

28582847
e_unlock:
28592848
sev_unlock_two_vms(kvm, source_kvm);
2860-
e_source_fput:
2861-
fdput(f);
28622849
return ret;
28632850
}
28642851

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,26 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
3535
int fd,
3636
int32_t priority)
3737
{
38-
struct fd f = fdget(fd);
38+
CLASS(fd, f)(fd);
3939
struct amdgpu_fpriv *fpriv;
4040
struct amdgpu_ctx_mgr *mgr;
4141
struct amdgpu_ctx *ctx;
4242
uint32_t id;
4343
int r;
4444

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

4848
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
49-
if (r) {
50-
fdput(f);
49+
if (r)
5150
return r;
52-
}
5351

5452
mgr = &fpriv->ctx_mgr;
5553
mutex_lock(&mgr->lock);
5654
idr_for_each_entry(&mgr->ctx_handles, ctx, id)
5755
amdgpu_ctx_priority_override(ctx, priority);
5856
mutex_unlock(&mgr->lock);
5957

60-
fdput(f);
6158
return 0;
6259
}
6360

@@ -66,31 +63,25 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
6663
unsigned ctx_id,
6764
int32_t priority)
6865
{
69-
struct fd f = fdget(fd);
66+
CLASS(fd, f)(fd);
7067
struct amdgpu_fpriv *fpriv;
7168
struct amdgpu_ctx *ctx;
7269
int r;
7370

74-
if (!fd_file(f))
71+
if (fd_empty(f))
7572
return -EINVAL;
7673

7774
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
78-
if (r) {
79-
fdput(f);
75+
if (r)
8076
return r;
81-
}
8277

8378
ctx = amdgpu_ctx_get(fpriv, ctx_id);
8479

85-
if (!ctx) {
86-
fdput(f);
80+
if (!ctx)
8781
return -EINVAL;
88-
}
8982

9083
amdgpu_ctx_priority_override(ctx, priority);
9184
amdgpu_ctx_put(ctx);
92-
fdput(f);
93-
9485
return 0;
9586
}
9687

drivers/gpu/drm/drm_syncobj.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,16 +712,14 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
712712
int fd, u32 *handle)
713713
{
714714
struct drm_syncobj *syncobj;
715-
struct fd f = fdget(fd);
715+
CLASS(fd, f)(fd);
716716
int ret;
717717

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

721-
if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
722-
fdput(f);
721+
if (fd_file(f)->f_op != &drm_syncobj_file_fops)
723722
return -EINVAL;
724-
}
725723

726724
/* take a reference to put in the idr */
727725
syncobj = fd_file(f)->private_data;
@@ -739,7 +737,6 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
739737
} else
740738
drm_syncobj_put(syncobj);
741739

742-
fdput(f);
743740
return ret;
744741
}
745742

0 commit comments

Comments
 (0)