[RFC PATCH v3 04/13] io_uring: add data to dma-buf conversion helpers

From: Nitesh Shetty

Date: Tue Dec 01 2026 - 11:55:46 EST


From: Pavel Begunkov <asml.silence@xxxxxxxxx>

struct io_buf_dma is stored as void * in registered buffers and cast in
several places.
Casts from void * aren't type checked, so wrap them in helpers.
No functional changes.

Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers")
Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
Signed-off-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx>
Signed-off-by: Nitesh Shetty <nj.shetty@xxxxxxxxxxx>
---
io_uring/dma-buf.c | 2 +-
io_uring/dma-buf.h | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index 61825d59e384..fd9b8769818a 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -2,7 +2,7 @@

static inline void io_release_dmabuf(void *priv)
{
- struct io_buf_dma *bd = priv;
+ struct io_buf_dma *bd = io_priv_to_dmabuf(priv);

fput(bd->target_file);
dma_buf_io_ctx_release(bd->ctx);
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index d8d9b4f224d8..051483991090 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -12,6 +12,16 @@ struct io_buf_dma {
struct file *target_file;
};

+static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
+{
+ return data;
+}
+
+static inline struct io_buf_dma *io_buf_to_dmabuf(struct io_mapped_ubuf *imu)
+{
+ return io_priv_to_dmabuf(imu->priv);
+}
+
int __io_register_dmabuf(struct io_ring_ctx *ctx,
struct io_uring_regbuf_desc *desc,
struct io_mapped_ubuf *imu);
@@ -39,7 +49,7 @@ static inline int io_attach_dmabuf_map(struct io_kiocb *req,
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;

- bd = req->buf_node->buf->priv;
+ bd = io_buf_to_dmabuf(req->buf_node->buf);
map = dma_buf_io_get_map(bd->ctx, nowait);
if (unlikely(IS_ERR(map)))
return PTR_ERR(map);
@@ -53,7 +63,7 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
struct io_mapped_ubuf *imu,
size_t len, size_t offset)
{
- struct io_buf_dma *bd = imu->priv;
+ struct io_buf_dma *bd = io_buf_to_dmabuf(imu);

if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
--
2.47.3