@@ -282,8 +282,6 @@ EXPORT_SYMBOL_GPL(media_request_get_by_fd);
282282int media_request_alloc (struct media_device * mdev , int * alloc_fd )
283283{
284284 struct media_request * req ;
285- struct file * filp ;
286- int fd ;
287285 int ret ;
288286
289287 /* Either both are NULL or both are non-NULL */
@@ -297,19 +295,6 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
297295 if (!req )
298296 return - ENOMEM ;
299297
300- fd = get_unused_fd_flags (O_CLOEXEC );
301- if (fd < 0 ) {
302- ret = fd ;
303- goto err_free_req ;
304- }
305-
306- filp = anon_inode_getfile ("request" , & request_fops , NULL , O_CLOEXEC );
307- if (IS_ERR (filp )) {
308- ret = PTR_ERR (filp );
309- goto err_put_fd ;
310- }
311-
312- filp -> private_data = req ;
313298 req -> mdev = mdev ;
314299 req -> state = MEDIA_REQUEST_STATE_IDLE ;
315300 req -> num_incomplete_objects = 0 ;
@@ -320,19 +305,24 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
320305 req -> updating_count = 0 ;
321306 req -> access_count = 0 ;
322307
323- * alloc_fd = fd ;
308+ FD_PREPARE (fdf , O_CLOEXEC ,
309+ anon_inode_getfile ("request" , & request_fops , NULL ,
310+ O_CLOEXEC ));
311+ if (fdf .err ) {
312+ ret = fdf .err ;
313+ goto err_free_req ;
314+ }
315+
316+ fd_prepare_file (fdf )-> private_data = req ;
317+
318+ * alloc_fd = fd_publish (fdf );
324319
325320 snprintf (req -> debug_str , sizeof (req -> debug_str ), "%u:%d" ,
326- atomic_inc_return (& mdev -> request_id ), fd );
321+ atomic_inc_return (& mdev -> request_id ), * alloc_fd );
327322 dev_dbg (mdev -> dev , "request: allocated %s\n" , req -> debug_str );
328323
329- fd_install (fd , filp );
330-
331324 return 0 ;
332325
333- err_put_fd :
334- put_unused_fd (fd );
335-
336326err_free_req :
337327 if (mdev -> ops -> req_free )
338328 mdev -> ops -> req_free (req );
0 commit comments