All drivers that use dma-bufs have been moved to the updated locking
specification and now dma-buf reservation is guaranteed to be locked
by importers during the mapping operations. There is no need to take
the internal dma-buf lock anymore. Remove locking from the videobuf2
memory allocators.

Acked-by: Tomasz Figa <tf...@chromium.org>
Acked-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
Acked-by: Christian König <christian.koe...@amd.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipe...@collabora.com>
---
 drivers/media/common/videobuf2/videobuf2-dma-contig.c | 11 +----------
 drivers/media/common/videobuf2/videobuf2-dma-sg.c     | 11 +----------
 drivers/media/common/videobuf2/videobuf2-vmalloc.c    | 11 +----------
 3 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c 
b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index 79f4d8301fbb..555bd40fa472 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -382,18 +382,12 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
        struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
 {
        struct vb2_dc_attachment *attach = db_attach->priv;
-       /* stealing dmabuf mutex to serialize map/unmap operations */
-       struct mutex *lock = &db_attach->dmabuf->lock;
        struct sg_table *sgt;
 
-       mutex_lock(lock);
-
        sgt = &attach->sgt;
        /* return previously mapped sg table */
-       if (attach->dma_dir == dma_dir) {
-               mutex_unlock(lock);
+       if (attach->dma_dir == dma_dir)
                return sgt;
-       }
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
@@ -409,14 +403,11 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
        if (dma_map_sgtable(db_attach->dev, sgt, dma_dir,
                            DMA_ATTR_SKIP_CPU_SYNC)) {
                pr_err("failed to map scatterlist\n");
-               mutex_unlock(lock);
                return ERR_PTR(-EIO);
        }
 
        attach->dma_dir = dma_dir;
 
-       mutex_unlock(lock);
-
        return sgt;
 }
 
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c 
b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index 36ecdea8d707..36981a5b5c53 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -424,18 +424,12 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
        struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
 {
        struct vb2_dma_sg_attachment *attach = db_attach->priv;
-       /* stealing dmabuf mutex to serialize map/unmap operations */
-       struct mutex *lock = &db_attach->dmabuf->lock;
        struct sg_table *sgt;
 
-       mutex_lock(lock);
-
        sgt = &attach->sgt;
        /* return previously mapped sg table */
-       if (attach->dma_dir == dma_dir) {
-               mutex_unlock(lock);
+       if (attach->dma_dir == dma_dir)
                return sgt;
-       }
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
@@ -446,14 +440,11 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
        /* mapping to the client with new direction */
        if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
                pr_err("failed to map scatterlist\n");
-               mutex_unlock(lock);
                return ERR_PTR(-EIO);
        }
 
        attach->dma_dir = dma_dir;
 
-       mutex_unlock(lock);
-
        return sgt;
 }
 
diff --git a/drivers/media/common/videobuf2/videobuf2-vmalloc.c 
b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
index 7831bf545874..41db707e43a4 100644
--- a/drivers/media/common/videobuf2/videobuf2-vmalloc.c
+++ b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
@@ -267,18 +267,12 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
        struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
 {
        struct vb2_vmalloc_attachment *attach = db_attach->priv;
-       /* stealing dmabuf mutex to serialize map/unmap operations */
-       struct mutex *lock = &db_attach->dmabuf->lock;
        struct sg_table *sgt;
 
-       mutex_lock(lock);
-
        sgt = &attach->sgt;
        /* return previously mapped sg table */
-       if (attach->dma_dir == dma_dir) {
-               mutex_unlock(lock);
+       if (attach->dma_dir == dma_dir)
                return sgt;
-       }
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
@@ -289,14 +283,11 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
        /* mapping to the client with new direction */
        if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
                pr_err("failed to map scatterlist\n");
-               mutex_unlock(lock);
                return ERR_PTR(-EIO);
        }
 
        attach->dma_dir = dma_dir;
 
-       mutex_unlock(lock);
-
        return sgt;
 }
 
-- 
2.37.3

Reply via email to