Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: add io_reset_rsrc_node() helper

Puts and reset an existing node in a slot, if one exists. Returns true
if a node was there, false if not. This helps cleanup some of the code
that does a lookup just to clear an existing node.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+17 -16
+3 -7
io_uring/filetable.c
··· 58 58 u32 slot_index) 59 59 __must_hold(&req->ctx->uring_lock) 60 60 { 61 - struct io_rsrc_node *node, *old_node; 61 + struct io_rsrc_node *node; 62 62 63 63 if (io_is_uring_fops(file)) 64 64 return -EBADF; ··· 71 71 if (!node) 72 72 return -ENOMEM; 73 73 74 - old_node = io_rsrc_node_lookup(&ctx->file_table.data, slot_index); 75 - if (old_node) 76 - io_put_rsrc_node(old_node); 77 - else 74 + if (!io_reset_rsrc_node(&ctx->file_table.data, slot_index)) 78 75 io_file_bitmap_set(&ctx->file_table, slot_index); 79 76 80 77 ctx->file_table.data.nodes[slot_index] = node; ··· 130 133 node = io_rsrc_node_lookup(&ctx->file_table.data, offset); 131 134 if (!node) 132 135 return -EBADF; 133 - io_put_rsrc_node(node); 134 - ctx->file_table.data.nodes[offset] = NULL; 136 + io_reset_rsrc_node(&ctx->file_table.data, offset); 135 137 io_file_bitmap_clear(&ctx->file_table, offset); 136 138 return 0; 137 139 }
+3 -9
io_uring/rsrc.c
··· 181 181 return -EINVAL; 182 182 183 183 for (done = 0; done < nr_args; done++) { 184 - struct io_rsrc_node *node; 185 184 u64 tag = 0; 186 185 187 186 if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) || ··· 196 197 continue; 197 198 198 199 i = up->offset + done; 199 - node = io_rsrc_node_lookup(&ctx->file_table.data, i); 200 - if (node) { 201 - io_put_rsrc_node(node); 202 - ctx->file_table.data.nodes[i] = NULL; 200 + if (io_reset_rsrc_node(&ctx->file_table.data, i)) 203 201 io_file_bitmap_clear(&ctx->file_table, i); 204 - } 202 + 205 203 if (fd != -1) { 206 204 struct file *file = fget(fd); 207 205 struct io_rsrc_node *node; ··· 275 279 break; 276 280 } 277 281 i = array_index_nospec(up->offset + done, ctx->buf_table.nr); 278 - if (ctx->buf_table.nodes[i]) 279 - io_put_rsrc_node(ctx->buf_table.nodes[i]); 280 - 282 + io_reset_rsrc_node(&ctx->buf_table, i); 281 283 ctx->buf_table.nodes[i] = node; 282 284 if (tag) 283 285 node->tag = tag;
+11
io_uring/rsrc.h
··· 84 84 io_free_rsrc_node(node); 85 85 } 86 86 87 + static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index) 88 + { 89 + struct io_rsrc_node *node = data->nodes[index]; 90 + 91 + if (!node) 92 + return false; 93 + io_put_rsrc_node(node); 94 + data->nodes[index] = NULL; 95 + return true; 96 + } 97 + 87 98 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req) 88 99 { 89 100 if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) {