@@ -23,6 +23,8 @@ struct io_rsrc_update {
2323 u32 offset ;
2424};
2525
26+ static void io_rsrc_buf_put (struct io_ring_ctx * ctx , struct io_rsrc_put * prsrc );
27+ static void io_rsrc_file_put (struct io_ring_ctx * ctx , struct io_rsrc_put * prsrc );
2628static int io_sqe_buffer_register (struct io_ring_ctx * ctx , struct iovec * iov ,
2729 struct io_mapped_ubuf * * pimu ,
2830 struct page * * last_hpage );
@@ -147,7 +149,18 @@ static void io_rsrc_put_work(struct io_rsrc_node *node)
147149
148150 if (prsrc -> tag )
149151 io_post_aux_cqe (data -> ctx , prsrc -> tag , 0 , 0 );
150- data -> do_put (data -> ctx , prsrc );
152+
153+ switch (data -> rsrc_type ) {
154+ case IORING_RSRC_FILE :
155+ io_rsrc_file_put (data -> ctx , prsrc );
156+ break ;
157+ case IORING_RSRC_BUFFER :
158+ io_rsrc_buf_put (data -> ctx , prsrc );
159+ break ;
160+ default :
161+ WARN_ON_ONCE (1 );
162+ break ;
163+ }
151164}
152165
153166void io_rsrc_node_destroy (struct io_ring_ctx * ctx , struct io_rsrc_node * node )
@@ -297,8 +310,8 @@ static __cold void **io_alloc_page_table(size_t size)
297310 return table ;
298311}
299312
300- __cold static int io_rsrc_data_alloc (struct io_ring_ctx * ctx ,
301- rsrc_put_fn * do_put , u64 __user * utags ,
313+ __cold static int io_rsrc_data_alloc (struct io_ring_ctx * ctx , int type ,
314+ u64 __user * utags ,
302315 unsigned nr , struct io_rsrc_data * * pdata )
303316{
304317 struct io_rsrc_data * data ;
@@ -316,7 +329,7 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
316329
317330 data -> nr = nr ;
318331 data -> ctx = ctx ;
319- data -> do_put = do_put ;
332+ data -> rsrc_type = type ;
320333 if (utags ) {
321334 ret = - EFAULT ;
322335 for (i = 0 ; i < nr ; i ++ ) {
@@ -849,7 +862,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
849862 return - EMFILE ;
850863 if (nr_args > rlimit (RLIMIT_NOFILE ))
851864 return - EMFILE ;
852- ret = io_rsrc_data_alloc (ctx , io_rsrc_file_put , tags , nr_args ,
865+ ret = io_rsrc_data_alloc (ctx , IORING_RSRC_FILE , tags , nr_args ,
853866 & ctx -> file_data );
854867 if (ret )
855868 return ret ;
@@ -1184,7 +1197,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
11841197 return - EBUSY ;
11851198 if (!nr_args || nr_args > IORING_MAX_REG_BUFFERS )
11861199 return - EINVAL ;
1187- ret = io_rsrc_data_alloc (ctx , io_rsrc_buf_put , tags , nr_args , & data );
1200+ ret = io_rsrc_data_alloc (ctx , IORING_RSRC_BUFFER , tags , nr_args , & data );
11881201 if (ret )
11891202 return ret ;
11901203 ret = io_buffers_map_alloc (ctx , nr_args );
0 commit comments