* [PATCH] io_uring/rsrc: avoid NULL check in io_put_rsrc_node()
@ 2025-02-16 22:58 Caleb Sander Mateos
2025-02-17 12:46 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Caleb Sander Mateos @ 2025-02-16 22:58 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: Caleb Sander Mateos, io-uring, linux-kernel
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 <[email protected]>
---
io_uring/rsrc.h | 2 +-
io_uring/splice.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 190f7ee45de9..a6d883c62b22 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -81,11 +81,11 @@ 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);
}
static inline bool io_reset_rsrc_node(struct io_ring_ctx *ctx,
struct io_rsrc_data *data, int index)
diff --git a/io_uring/splice.c b/io_uring/splice.c
index 5b84f1630611..7b89bd84d486 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -49,11 +49,12 @@ int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
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,
unsigned int issue_flags)
{
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring/rsrc: avoid NULL check in io_put_rsrc_node()
2025-02-16 22:58 [PATCH] io_uring/rsrc: avoid NULL check in io_put_rsrc_node() Caleb Sander Mateos
@ 2025-02-17 12:46 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-02-17 12:46 UTC (permalink / raw)
To: Pavel Begunkov, Caleb Sander Mateos; +Cc: io-uring, linux-kernel
On Sun, 16 Feb 2025 15:58:59 -0700, Caleb Sander Mateos wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] io_uring/rsrc: avoid NULL check in io_put_rsrc_node()
commit: 496f56bf9f1acf11ce14489f34d81ba6e4023f42
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-17 12:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-16 22:58 [PATCH] io_uring/rsrc: avoid NULL check in io_put_rsrc_node() Caleb Sander Mateos
2025-02-17 12:46 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox