@@ -93,7 +93,7 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)
9393 struct handshake_net * hn = handshake_pernet (net );
9494 struct handshake_req * req = NULL ;
9595 struct socket * sock ;
96- int class , fd , err ;
96+ int class , err ;
9797
9898 err = - EOPNOTSUPP ;
9999 if (!hn )
@@ -106,27 +106,25 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)
106106
107107 err = - EAGAIN ;
108108 req = handshake_req_next (hn , class );
109- if (!req )
110- goto out_status ;
111-
112- sock = req -> hr_sk -> sk_socket ;
113- fd = get_unused_fd_flags (O_CLOEXEC );
114- if (fd < 0 ) {
115- err = fd ;
116- goto out_complete ;
117- }
118-
119- err = req -> hr_proto -> hp_accept (req , info , fd );
120- if (err ) {
121- put_unused_fd (fd );
122- goto out_complete ;
109+ if (req ) {
110+ sock = req -> hr_sk -> sk_socket ;
111+
112+ FD_PREPARE (fdf , O_CLOEXEC , sock -> file );
113+ if (fdf .err ) {
114+ err = fdf .err ;
115+ goto out_complete ;
116+ }
117+
118+ get_file (sock -> file ); /* FD_PREPARE() consumes a reference. */
119+ err = req -> hr_proto -> hp_accept (req , info , fd_prepare_fd (fdf ));
120+ if (err )
121+ goto out_complete ; /* Automatic cleanup handles fput */
122+
123+ trace_handshake_cmd_accept (net , req , req -> hr_sk , fd_prepare_fd (fdf ));
124+ fd_publish (fdf );
125+ return 0 ;
123126 }
124127
125- fd_install (fd , get_file (sock -> file ));
126-
127- trace_handshake_cmd_accept (net , req , req -> hr_sk , fd );
128- return 0 ;
129-
130128out_complete :
131129 handshake_complete (req , - EIO , NULL );
132130out_status :
0 commit comments