u32 slot_index)
__must_hold(&req->ctx->uring_lock)
{
- struct io_rsrc_node *node, *old_node;
+ struct io_rsrc_node *node;
if (io_is_uring_fops(file))
return -EBADF;
if (!node)
return -ENOMEM;
- old_node = io_rsrc_node_lookup(&ctx->file_table.data, slot_index);
- if (old_node)
- io_put_rsrc_node(old_node);
- else
+ if (!io_reset_rsrc_node(&ctx->file_table.data, slot_index))
io_file_bitmap_set(&ctx->file_table, slot_index);
ctx->file_table.data.nodes[slot_index] = node;
node = io_rsrc_node_lookup(&ctx->file_table.data, offset);
if (!node)
return -EBADF;
- io_put_rsrc_node(node);
- ctx->file_table.data.nodes[offset] = NULL;
+ io_reset_rsrc_node(&ctx->file_table.data, offset);
io_file_bitmap_clear(&ctx->file_table, offset);
return 0;
}
return -EINVAL;
for (done = 0; done < nr_args; done++) {
- struct io_rsrc_node *node;
u64 tag = 0;
if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) ||
continue;
i = up->offset + done;
- node = io_rsrc_node_lookup(&ctx->file_table.data, i);
- if (node) {
- io_put_rsrc_node(node);
- ctx->file_table.data.nodes[i] = NULL;
+ if (io_reset_rsrc_node(&ctx->file_table.data, i))
io_file_bitmap_clear(&ctx->file_table, i);
- }
+
if (fd != -1) {
struct file *file = fget(fd);
struct io_rsrc_node *node;
break;
}
i = array_index_nospec(up->offset + done, ctx->buf_table.nr);
- if (ctx->buf_table.nodes[i])
- io_put_rsrc_node(ctx->buf_table.nodes[i]);
-
+ io_reset_rsrc_node(&ctx->buf_table, i);
ctx->buf_table.nodes[i] = node;
if (tag)
node->tag = tag;
io_free_rsrc_node(node);
}
+static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
+{
+ struct io_rsrc_node *node = data->nodes[index];
+
+ if (!node)
+ return false;
+ io_put_rsrc_node(node);
+ data->nodes[index] = NULL;
+ return true;
+}
+
static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
{
if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) {