@@ -479,10 +479,7 @@ static const struct file_operations papr_hvpipe_handle_ops = {
479479
480480static int papr_hvpipe_dev_create_handle (u32 srcID )
481481{
482- struct hvpipe_source_info * src_info ;
483- struct file * file ;
484- long err ;
485- int fd ;
482+ struct hvpipe_source_info * src_info __free (kfree ) = NULL ;
486483
487484 spin_lock (& hvpipe_src_list_lock );
488485 /*
@@ -506,20 +503,13 @@ static int papr_hvpipe_dev_create_handle(u32 srcID)
506503 src_info -> tsk = current ;
507504 init_waitqueue_head (& src_info -> recv_wqh );
508505
509- fd = get_unused_fd_flags (O_RDONLY | O_CLOEXEC );
510- if (fd < 0 ) {
511- err = fd ;
512- goto free_buf ;
513- }
514-
515- file = anon_inode_getfile ("[papr-hvpipe]" ,
516- & papr_hvpipe_handle_ops , (void * )src_info ,
517- O_RDWR );
518- if (IS_ERR (file )) {
519- err = PTR_ERR (file );
520- goto free_fd ;
521- }
506+ FD_PREPARE (fdf , O_RDONLY | O_CLOEXEC ,
507+ anon_inode_getfile ("[papr-hvpipe]" , & papr_hvpipe_handle_ops ,
508+ (void * )src_info , O_RDWR ));
509+ if (fdf .err )
510+ return fdf .err ;
522511
512+ retain_and_null_ptr (src_info );
523513 spin_lock (& hvpipe_src_list_lock );
524514 /*
525515 * If two processes are executing ioctl() for the same
@@ -528,22 +518,11 @@ static int papr_hvpipe_dev_create_handle(u32 srcID)
528518 */
529519 if (hvpipe_find_source (srcID )) {
530520 spin_unlock (& hvpipe_src_list_lock );
531- err = - EALREADY ;
532- goto free_file ;
521+ return - EALREADY ;
533522 }
534523 list_add (& src_info -> list , & hvpipe_src_list );
535524 spin_unlock (& hvpipe_src_list_lock );
536-
537- fd_install (fd , file );
538- return fd ;
539-
540- free_file :
541- fput (file );
542- free_fd :
543- put_unused_fd (fd );
544- free_buf :
545- kfree (src_info );
546- return err ;
525+ return fd_publish (fdf );
547526}
548527
549528/*
0 commit comments