linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2 0/3] Fix handling of sg_table struct
@ 2015-04-29 12:00 Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure Ricardo Ribalda Delgado
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-04-29 12:00 UTC (permalink / raw)
  To: Hans Verkuil, Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Ricardo Ribalda Delgado

This is just a resend of the previous patches, cherry-picked to
the last master media tree.

I have also added the Reviewed-by: Marek

Thanks

Ricardo Ribalda Delgado (3):
  media/videobuf2-dma-sg: Fix handling of sg_table structure
  media/videobuf2-dma-contig: Save output from dma_map_sg
  media/videobuf2-dma-vmalloc: Save output from dma_map_sg

 drivers/media/v4l2-core/videobuf2-dma-contig.c |  6 +++---
 drivers/media/v4l2-core/videobuf2-dma-sg.c     | 22 +++++++++++++---------
 drivers/media/v4l2-core/videobuf2-vmalloc.c    |  6 +++---
 3 files changed, 19 insertions(+), 15 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure
  2015-04-29 12:00 [RESEND PATCH v2 0/3] Fix handling of sg_table struct Ricardo Ribalda Delgado
@ 2015-04-29 12:00 ` Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 2/3] media/videobuf2-dma-contig: Save output from dma_map_sg Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 3/3] media/videobuf2-dma-vmalloc: " Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-04-29 12:00 UTC (permalink / raw)
  To: Hans Verkuil, Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Ricardo Ribalda

From: Ricardo Ribalda <ricardo.ribalda@gmail.com>

When sg_alloc_table_from_pages() does not fail it returns a sg_table
structure with nents and nents_orig initialized to the same value.

dma_map_sg returns the number of areas mapped by the hardware,
which could be different than the areas given as an input.
The output must be saved to nent.

The output of dma_map, should be used to transverse the scatter list.

dma_unmap_sg needs the value passed to dma_map_sg (nents_orig).

sg_free_tables uses also orig_nent.

This patch fix the file to follow this paradigm.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 45c708e463b9..7289b81bd7b7 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -147,8 +147,9 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size,
 	 * No need to sync to the device, this will happen later when the
 	 * prepare() memop is called.
 	 */
-	if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents,
-			     buf->dma_dir, &attrs) == 0)
+	sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
+				      buf->dma_dir, &attrs);
+	if (!sgt->nents)
 		goto fail_map;
 
 	buf->handler.refcount = &buf->refcount;
@@ -187,7 +188,7 @@ static void vb2_dma_sg_put(void *buf_priv)
 		dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs);
 		dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
 			buf->num_pages);
-		dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents,
+		dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
 				   buf->dma_dir, &attrs);
 		if (buf->vaddr)
 			vm_unmap_ram(buf->vaddr, buf->num_pages);
@@ -314,9 +315,11 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
 	 * No need to sync to the device, this will happen later when the
 	 * prepare() memop is called.
 	 */
-	if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents,
-			     buf->dma_dir, &attrs) == 0)
+	sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
+				      buf->dma_dir, &attrs);
+	if (!sgt->nents)
 		goto userptr_fail_map;
+
 	return buf;
 
 userptr_fail_map:
@@ -351,7 +354,8 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
 
 	dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
 	       __func__, buf->num_pages);
-	dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir, &attrs);
+	dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir,
+			   &attrs);
 	if (buf->vaddr)
 		vm_unmap_ram(buf->vaddr, buf->num_pages);
 	sg_free_table(buf->dma_sgt);
@@ -502,7 +506,6 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
 	/* stealing dmabuf mutex to serialize map/unmap operations */
 	struct mutex *lock = &db_attach->dmabuf->lock;
 	struct sg_table *sgt;
-	int ret;
 
 	mutex_lock(lock);
 
@@ -521,8 +524,9 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
 	}
 
 	/* mapping to the client with new direction */
-	ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir);
-	if (ret <= 0) {
+	sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
+				dma_dir);
+	if (!sgt->nents) {
 		pr_err("failed to map scatterlist\n");
 		mutex_unlock(lock);
 		return ERR_PTR(-EIO);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RESEND PATCH v2 2/3] media/videobuf2-dma-contig: Save output from dma_map_sg
  2015-04-29 12:00 [RESEND PATCH v2 0/3] Fix handling of sg_table struct Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure Ricardo Ribalda Delgado
@ 2015-04-29 12:00 ` Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 3/3] media/videobuf2-dma-vmalloc: " Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-04-29 12:00 UTC (permalink / raw)
  To: Hans Verkuil, Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Ricardo Ribalda

From: Ricardo Ribalda <ricardo.ribalda@gmail.com>

dma_map_sg returns the number of areas mapped by the hardware,
which could be different than the areas given as an input.
The output must be saved to nent.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 644dec73d220..94c1e6455d36 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -299,7 +299,6 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
 	/* stealing dmabuf mutex to serialize map/unmap operations */
 	struct mutex *lock = &db_attach->dmabuf->lock;
 	struct sg_table *sgt;
-	int ret;
 
 	mutex_lock(lock);
 
@@ -318,8 +317,9 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
 	}
 
 	/* mapping to the client with new direction */
-	ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir);
-	if (ret <= 0) {
+	sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
+				dma_dir);
+	if (!sgt->nents) {
 		pr_err("failed to map scatterlist\n");
 		mutex_unlock(lock);
 		return ERR_PTR(-EIO);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RESEND PATCH v2 3/3] media/videobuf2-dma-vmalloc: Save output from dma_map_sg
  2015-04-29 12:00 [RESEND PATCH v2 0/3] Fix handling of sg_table struct Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure Ricardo Ribalda Delgado
  2015-04-29 12:00 ` [RESEND PATCH v2 2/3] media/videobuf2-dma-contig: Save output from dma_map_sg Ricardo Ribalda Delgado
@ 2015-04-29 12:00 ` Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-04-29 12:00 UTC (permalink / raw)
  To: Hans Verkuil, Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Ricardo Ribalda

From: Ricardo Ribalda <ricardo.ribalda@gmail.com>

dma_map_sg returns the number of areas mapped by the hardware,
which could be different than the areas given as an input.
The output must be saved to nent.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/media/v4l2-core/videobuf2-vmalloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 657ab302a5cf..2fe4c27f524a 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -287,7 +287,6 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
 	/* stealing dmabuf mutex to serialize map/unmap operations */
 	struct mutex *lock = &db_attach->dmabuf->lock;
 	struct sg_table *sgt;
-	int ret;
 
 	mutex_lock(lock);
 
@@ -306,8 +305,9 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
 	}
 
 	/* mapping to the client with new direction */
-	ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir);
-	if (ret <= 0) {
+	sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
+				dma_dir);
+	if (!sgt->nents) {
 		pr_err("failed to map scatterlist\n");
 		mutex_unlock(lock);
 		return ERR_PTR(-EIO);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-29 12:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29 12:00 [RESEND PATCH v2 0/3] Fix handling of sg_table struct Ricardo Ribalda Delgado
2015-04-29 12:00 ` [RESEND PATCH v2 1/3] media/videobuf2-dma-sg: Fix handling of sg_table structure Ricardo Ribalda Delgado
2015-04-29 12:00 ` [RESEND PATCH v2 2/3] media/videobuf2-dma-contig: Save output from dma_map_sg Ricardo Ribalda Delgado
2015-04-29 12:00 ` [RESEND PATCH v2 3/3] media/videobuf2-dma-vmalloc: " Ricardo Ribalda Delgado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).