Now struct io_buf_dma only stores dma_buf_io_ctx, and we can use the
latter directly.

Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers")
Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/dma-buf.c | 16 ++++------------
 io_uring/dma-buf.h | 16 ++++++----------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index f25749f7da22..a1fc34c0c044 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -2,17 +2,14 @@
 
 static inline void io_release_dmabuf(void *priv)
 {
-       struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
-
-       dma_buf_io_ctx_release(bd->ctx);
-       kfree(bd);
+       dma_buf_io_ctx_release(io_priv_to_dmabuf(priv));
 }
 
 int __io_register_dmabuf(struct io_ring_ctx *ctx,
                        struct io_uring_regbuf_desc *desc,
                        struct io_mapped_ubuf *imu)
 {
-       struct io_buf_dma *bd = NULL;
+       struct dma_buf_io_ctx *dmabuf_ctx;
        struct file *target_file = NULL;
        struct dma_buf *dmabuf = NULL;
        int ret;
@@ -27,10 +24,6 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
        if (desc->uaddr || desc->size)
                return -EINVAL;
 
-       bd = kzalloc(sizeof(*bd), GFP_KERNEL);
-       if (!bd)
-               return -ENOMEM;
-
        target_file = fget(desc->target_fd);
        if (!target_file) {
                ret = -EBADF;
@@ -47,20 +40,19 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
                goto err;
 
        ret = dma_buf_io_ctx_create(target_file, dmabuf, DMA_BIDIRECTIONAL,
-                                   &bd->ctx);
+                                   &dmabuf_ctx);
        if (ret)
                goto err;
 
        imu->len = dmabuf->size;
        imu->release = io_release_dmabuf;
-       imu->priv = bd;
+       imu->priv = dmabuf_ctx;
        imu->flags = IO_REGBUF_F_DMABUF;
        imu->dir = IO_BUF_DEST | IO_BUF_SOURCE;
        dma_buf_put(dmabuf);
        fput(target_file);
        return 0;
 err:
-       kfree(bd);
        if (target_file)
                fput(target_file);
        if (dmabuf)
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index 9bd7c8c64397..c622347fbd76 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -7,16 +7,12 @@
 
 #include "rsrc.h"
 
-struct io_buf_dma {
-       struct dma_buf_io_ctx           *ctx;
-};
-
-static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
+static inline struct dma_buf_io_ctx *io_priv_to_dmabuf(void *data)
 {
        return data;
 }
 
-static inline struct io_buf_dma *io_buf_to_dmabuf(struct io_mapped_ubuf *imu)
+static inline struct dma_buf_io_ctx *io_buf_to_dmabuf(struct io_mapped_ubuf 
*imu)
 {
        return io_priv_to_dmabuf(imu->priv);
 }
@@ -40,16 +36,16 @@ static inline int io_attach_dmabuf_map(struct io_kiocb *req,
                                        unsigned issue_flags)
 {
        bool nowait = issue_flags & IO_URING_F_NONBLOCK;
+       struct io_mapped_ubuf *imu;
        struct dma_buf_io_map *map;
-       struct io_buf_dma *bd;
 
        if (!(req->flags & REQ_F_DMABUF))
                return 0;
        if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
                return -EOPNOTSUPP;
 
-       bd = io_buf_to_dmabuf(req->buf_node->buf);
-       map = dma_buf_io_get_map(bd->ctx, nowait);
+       imu = req->buf_node->buf;
+       map = dma_buf_io_get_map(io_buf_to_dmabuf(imu), nowait);
        if (unlikely(IS_ERR(map)))
                return PTR_ERR(map);
        req->dmabuf_map = map;
@@ -64,7 +60,7 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
 {
        if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
                return -EOPNOTSUPP;
-       if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu)->ctx,
+       if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu),
                                                 req->file)))
                return -EBADF;
        req->flags |= REQ_F_DMABUF;
-- 
2.54.0

Reply via email to