[PATCH v5 3/4] media: videobuf2-core: reverse the iteration order in __vb2_buf_dmabuf_put

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch prepares for allowing multiple planes to share the same DMA
buffer attachment.

Release the planes from num_planes - 1 to 0 so that we don't leave invalid
mem_priv pointers behind.

Signed-off-by: Yunke Cao <yunkec@xxxxxxxxxxxx>
Acked-by: Tomasz Figa <tfiga@xxxxxxxxxxxx>
---
v5:
- Add comment to explain why.
- Update commit message to explain why.

v3:
- Change local variable to an integer to make the code cleaner.
---
 drivers/media/common/videobuf2/videobuf2-core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index b53d94659e30..e6af963307e3 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -323,9 +323,15 @@ static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
  */
 static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
 {
-	unsigned int plane;
+	int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane)
+	/*
+	 * When multiple planes share the same DMA buffer attachment, the plane
+	 * with the lowest index owns the mem_priv.
+	 * Put planes in the reversed order so that we don't leave invalid
+	 * mem_priv behind.
+	 */
+	for (plane = vb->num_planes - 1; plane >= 0; --plane)
 		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
 }
 
-- 
2.46.0.184.g6999bdac58-goog





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux