@@ -172,22 +172,24 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags)
172172 return __io_msg_ring_data (target_ctx , msg , issue_flags );
173173}
174174
175- static struct file * io_msg_grab_file (struct io_kiocb * req , unsigned int issue_flags )
175+ static int io_msg_grab_file (struct io_kiocb * req , unsigned int issue_flags )
176176{
177177 struct io_msg * msg = io_kiocb_to_cmd (req , struct io_msg );
178178 struct io_ring_ctx * ctx = req -> ctx ;
179- struct file * file = NULL ;
180- int idx = msg -> src_fd ;
179+ struct io_rsrc_node * node ;
180+ int ret = - EBADF ;
181181
182182 io_ring_submit_lock (ctx , issue_flags );
183- if (likely (idx < ctx -> file_table .data .nr )) {
184- idx = array_index_nospec (idx , ctx -> file_table .data .nr );
185- file = io_file_from_index (& ctx -> file_table , idx );
186- if (file )
187- get_file (file );
183+ node = io_rsrc_node_lookup (& ctx -> file_table .data , msg -> src_fd );
184+ if (node ) {
185+ msg -> src_file = io_slot_file (node );
186+ if (msg -> src_file )
187+ get_file (msg -> src_file );
188+ req -> flags |= REQ_F_NEED_CLEANUP ;
189+ ret = 0 ;
188190 }
189191 io_ring_submit_unlock (ctx , issue_flags );
190- return file ;
192+ return ret ;
191193}
192194
193195static int io_msg_install_complete (struct io_kiocb * req , unsigned int issue_flags )
@@ -256,20 +258,17 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
256258 struct io_ring_ctx * target_ctx = req -> file -> private_data ;
257259 struct io_msg * msg = io_kiocb_to_cmd (req , struct io_msg );
258260 struct io_ring_ctx * ctx = req -> ctx ;
259- struct file * src_file = msg -> src_file ;
260261
261262 if (msg -> len )
262263 return - EINVAL ;
263264 if (target_ctx == ctx )
264265 return - EINVAL ;
265266 if (target_ctx -> flags & IORING_SETUP_R_DISABLED )
266267 return - EBADFD ;
267- if (!src_file ) {
268- src_file = io_msg_grab_file (req , issue_flags );
269- if (!src_file )
270- return - EBADF ;
271- msg -> src_file = src_file ;
272- req -> flags |= REQ_F_NEED_CLEANUP ;
268+ if (!msg -> src_file ) {
269+ int ret = io_msg_grab_file (req , issue_flags );
270+ if (unlikely (ret ))
271+ return ret ;
273272 }
274273
275274 if (io_msg_need_remote (target_ctx ))
0 commit comments