io_uring/rsrc: avoid NULL check in io_put_rsrc_node()
authorCaleb Sander Mateos <csander@purestorage.com>
Sun, 16 Feb 2025 22:58:59 +0000 (15:58 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 17 Feb 2025 12:34:46 +0000 (05:34 -0700)
Most callers of io_put_rsrc_node() already check that node is non-NULL:
- io_rsrc_data_free()
- io_sqe_buffer_register()
- io_reset_rsrc_node()
- io_req_put_rsrc_nodes() (REQ_F_BUF_NODE indicates non-NULL buf_node)

Only io_splice_cleanup() can call io_put_rsrc_node() with a NULL node.
So move the NULL check there.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Link: https://lore.kernel.org/r/20250216225900.1075446-1-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rsrc.h
io_uring/splice.c

index 190f7ee45de933b39a8c4d33dc86f687e338eb16..a6d883c62b2213a31586153b165e86cb22e5d28c 100644 (file)
@@ -83,7 +83,7 @@ static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data
 static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
 {
        lockdep_assert_held(&ctx->uring_lock);
-       if (node && !--node->refs)
+       if (!--node->refs)
                io_free_rsrc_node(ctx, node);
 }
 
index 5b84f16306116e4d5cc85de3013a058f0030c623..7b89bd84d486d480787cbc551c575c927bd27cda 100644 (file)
@@ -51,7 +51,8 @@ void io_splice_cleanup(struct io_kiocb *req)
 {
        struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
 
-       io_put_rsrc_node(req->ctx, sp->rsrc_node);
+       if (sp->rsrc_node)
+               io_put_rsrc_node(req->ctx, sp->rsrc_node);
 }
 
 static struct file *io_splice_get_file(struct io_kiocb *req,