File tree Expand file tree Collapse file tree 4 files changed +14
-47
lines changed Expand file tree Collapse file tree 4 files changed +14
-47
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,6 @@ int vfio_virqfd_enable(void *opaque,
113
113
void (* thread )(void * , void * ),
114
114
void * data , struct virqfd * * pvirqfd , int fd )
115
115
{
116
- struct fd irqfd ;
117
116
struct eventfd_ctx * ctx ;
118
117
struct virqfd * virqfd ;
119
118
int ret = 0 ;
@@ -133,16 +132,16 @@ int vfio_virqfd_enable(void *opaque,
133
132
INIT_WORK (& virqfd -> inject , virqfd_inject );
134
133
INIT_WORK (& virqfd -> flush_inject , virqfd_flush_inject );
135
134
136
- irqfd = fdget (fd );
137
- if (! fd_file (irqfd )) {
135
+ CLASS ( fd , irqfd ) (fd );
136
+ if (fd_empty (irqfd )) {
138
137
ret = - EBADF ;
139
138
goto err_fd ;
140
139
}
141
140
142
141
ctx = eventfd_ctx_fileget (fd_file (irqfd ));
143
142
if (IS_ERR (ctx )) {
144
143
ret = PTR_ERR (ctx );
145
- goto err_ctx ;
144
+ goto err_fd ;
146
145
}
147
146
148
147
virqfd -> eventfd = ctx ;
@@ -181,18 +180,9 @@ int vfio_virqfd_enable(void *opaque,
181
180
if ((!handler || handler (opaque , data )) && thread )
182
181
schedule_work (& virqfd -> inject );
183
182
}
184
-
185
- /*
186
- * Do not drop the file until the irqfd is fully initialized,
187
- * otherwise we might race against the EPOLLHUP.
188
- */
189
- fdput (irqfd );
190
-
191
183
return 0 ;
192
184
err_busy :
193
185
eventfd_ctx_put (ctx );
194
- err_ctx :
195
- fdput (irqfd );
196
186
err_fd :
197
187
kfree (virqfd );
198
188
Original file line number Diff line number Diff line change @@ -112,7 +112,6 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
112
112
struct eventfd_ctx * eventfd = NULL ;
113
113
struct hsm_irqfd * irqfd , * tmp ;
114
114
__poll_t events ;
115
- struct fd f ;
116
115
int ret = 0 ;
117
116
118
117
irqfd = kzalloc (sizeof (* irqfd ), GFP_KERNEL );
@@ -124,16 +123,16 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
124
123
INIT_LIST_HEAD (& irqfd -> list );
125
124
INIT_WORK (& irqfd -> shutdown , hsm_irqfd_shutdown_work );
126
125
127
- f = fdget (args -> fd );
128
- if (! fd_file (f )) {
126
+ CLASS ( fd , f ) (args -> fd );
127
+ if (fd_empty (f )) {
129
128
ret = - EBADF ;
130
129
goto out ;
131
130
}
132
131
133
132
eventfd = eventfd_ctx_fileget (fd_file (f ));
134
133
if (IS_ERR (eventfd )) {
135
134
ret = PTR_ERR (eventfd );
136
- goto fail ;
135
+ goto out ;
137
136
}
138
137
139
138
irqfd -> eventfd = eventfd ;
@@ -162,13 +161,9 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
162
161
if (events & EPOLLIN )
163
162
acrn_irqfd_inject (irqfd );
164
163
165
- fdput (f );
166
164
return 0 ;
167
165
fail :
168
- if (eventfd && !IS_ERR (eventfd ))
169
- eventfd_ctx_put (eventfd );
170
-
171
- fdput (f );
166
+ eventfd_ctx_put (eventfd );
172
167
out :
173
168
kfree (irqfd );
174
169
return ret ;
Original file line number Diff line number Diff line change @@ -967,10 +967,11 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
967
967
struct privcmd_kernel_irqfd * kirqfd , * tmp ;
968
968
unsigned long flags ;
969
969
__poll_t events ;
970
- struct fd f ;
971
970
void * dm_op ;
972
971
int ret , idx ;
973
972
973
+ CLASS (fd , f )(irqfd -> fd );
974
+
974
975
kirqfd = kzalloc (sizeof (* kirqfd ) + irqfd -> size , GFP_KERNEL );
975
976
if (!kirqfd )
976
977
return - ENOMEM ;
@@ -986,16 +987,15 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
986
987
kirqfd -> dom = irqfd -> dom ;
987
988
INIT_WORK (& kirqfd -> shutdown , irqfd_shutdown );
988
989
989
- f = fdget (irqfd -> fd );
990
- if (!fd_file (f )) {
990
+ if (fd_empty (f )) {
991
991
ret = - EBADF ;
992
992
goto error_kfree ;
993
993
}
994
994
995
995
kirqfd -> eventfd = eventfd_ctx_fileget (fd_file (f ));
996
996
if (IS_ERR (kirqfd -> eventfd )) {
997
997
ret = PTR_ERR (kirqfd -> eventfd );
998
- goto error_fd_put ;
998
+ goto error_kfree ;
999
999
}
1000
1000
1001
1001
/*
@@ -1028,20 +1028,11 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
1028
1028
irqfd_inject (kirqfd );
1029
1029
1030
1030
srcu_read_unlock (& irqfds_srcu , idx );
1031
-
1032
- /*
1033
- * Do not drop the file until the kirqfd is fully initialized, otherwise
1034
- * we might race against the EPOLLHUP.
1035
- */
1036
- fdput (f );
1037
1031
return 0 ;
1038
1032
1039
1033
error_eventfd :
1040
1034
eventfd_ctx_put (kirqfd -> eventfd );
1041
1035
1042
- error_fd_put :
1043
- fdput (f );
1044
-
1045
1036
error_kfree :
1046
1037
kfree (kirqfd );
1047
1038
return ret ;
Original file line number Diff line number Diff line change @@ -304,7 +304,6 @@ static int
304
304
kvm_irqfd_assign (struct kvm * kvm , struct kvm_irqfd * args )
305
305
{
306
306
struct kvm_kernel_irqfd * irqfd , * tmp ;
307
- struct fd f ;
308
307
struct eventfd_ctx * eventfd = NULL , * resamplefd = NULL ;
309
308
int ret ;
310
309
__poll_t events ;
@@ -327,16 +326,16 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
327
326
INIT_WORK (& irqfd -> shutdown , irqfd_shutdown );
328
327
seqcount_spinlock_init (& irqfd -> irq_entry_sc , & kvm -> irqfds .lock );
329
328
330
- f = fdget (args -> fd );
331
- if (! fd_file (f )) {
329
+ CLASS ( fd , f ) (args -> fd );
330
+ if (fd_empty (f )) {
332
331
ret = - EBADF ;
333
332
goto out ;
334
333
}
335
334
336
335
eventfd = eventfd_ctx_fileget (fd_file (f ));
337
336
if (IS_ERR (eventfd )) {
338
337
ret = PTR_ERR (eventfd );
339
- goto fail ;
338
+ goto out ;
340
339
}
341
340
342
341
irqfd -> eventfd = eventfd ;
@@ -440,12 +439,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
440
439
#endif
441
440
442
441
srcu_read_unlock (& kvm -> irq_srcu , idx );
443
-
444
- /*
445
- * do not drop the file until the irqfd is fully initialized, otherwise
446
- * we might race against the EPOLLHUP
447
- */
448
- fdput (f );
449
442
return 0 ;
450
443
451
444
fail :
@@ -458,8 +451,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
458
451
if (eventfd && !IS_ERR (eventfd ))
459
452
eventfd_ctx_put (eventfd );
460
453
461
- fdput (f );
462
-
463
454
out :
464
455
kfree (irqfd );
465
456
return ret ;
You can’t perform that action at this time.
0 commit comments