@@ -211,10 +211,9 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
211211 const struct file_operations * fops = & io_mock_fops ;
212212 const struct io_uring_sqe * sqe = cmd -> sqe ;
213213 struct io_uring_mock_create mc , __user * uarg ;
214- struct io_mock_file * mf = NULL ;
215- struct file * file = NULL ;
214+ struct file * file ;
215+ struct io_mock_file * mf __free ( kfree ) = NULL ;
216216 size_t uarg_size ;
217- int fd = -1 , ret ;
218217
219218 /*
220219 * It's a testing only driver that allows exercising edge cases
@@ -246,10 +245,6 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
246245 if (!mf )
247246 return - ENOMEM ;
248247
249- ret = fd = get_unused_fd_flags (O_RDWR | O_CLOEXEC );
250- if (fd < 0 )
251- goto fail ;
252-
253248 init_waitqueue_head (& mf -> poll_wq );
254249 mf -> size = mc .file_size ;
255250 mf -> rw_delay_ns = mc .rw_delay_ns ;
@@ -258,33 +253,25 @@ static int io_create_mock_file(struct io_uring_cmd *cmd, unsigned int issue_flag
258253 mf -> pollable = true;
259254 }
260255
261- file = anon_inode_create_getfile ("[io_uring_mock]" , fops ,
262- mf , O_RDWR | O_CLOEXEC , NULL );
263- if (IS_ERR (file )) {
264- ret = PTR_ERR (file );
265- goto fail ;
266- }
256+ FD_PREPARE (fdf , O_RDWR | O_CLOEXEC ,
257+ anon_inode_create_getfile ("[io_uring_mock]" , fops , mf ,
258+ O_RDWR | O_CLOEXEC , NULL ));
259+ if (fdf .err )
260+ return fdf .err ;
267261
268- file -> f_mode |= FMODE_READ | FMODE_CAN_READ |
269- FMODE_WRITE | FMODE_CAN_WRITE |
270- FMODE_LSEEK ;
262+ retain_and_null_ptr (mf );
263+ file = fd_prepare_file (fdf );
264+ file -> f_mode |= FMODE_READ | FMODE_CAN_READ | FMODE_WRITE |
265+ FMODE_CAN_WRITE | FMODE_LSEEK ;
271266 if (mc .flags & IORING_MOCK_CREATE_F_SUPPORT_NOWAIT )
272267 file -> f_mode |= FMODE_NOWAIT ;
273268
274- mc .out_fd = fd ;
275- if (copy_to_user (uarg , & mc , uarg_size )) {
276- fput (file );
277- ret = - EFAULT ;
278- goto fail ;
279- }
269+ mc .out_fd = fd_prepare_fd (fdf );
270+ if (copy_to_user (uarg , & mc , uarg_size ))
271+ return - EFAULT ;
280272
281- fd_install ( fd , file );
273+ fd_publish ( fdf );
282274 return 0 ;
283- fail :
284- if (fd >= 0 )
285- put_unused_fd (fd );
286- kfree (mf );
287- return ret ;
288275}
289276
290277static int io_probe_mock (struct io_uring_cmd * cmd )
0 commit comments