media: videobuf2-core: reverse the iteration order in __vb2_buf_dmabuf_put
authorYunke Cao <yunkec@chromium.org>
Wed, 14 Aug 2024 02:06:42 +0000 (11:06 +0900)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 14 Aug 2024 08:05:32 +0000 (10:05 +0200)
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@chromium.org>
Acked-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/common/videobuf2/videobuf2-core.c

index b53d94659e3068b0c00f6f75dd51723f41e6e3e8..e6af963307e35cd6bb9a0860e2af00cdefd4c51a 100644 (file)
@@ -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]);
 }