Skip to content

Commit 702a47c

Browse files
ambarushverkuil
authored andcommitted
media: videobuf2-core: copy vb planes unconditionally
Copy the relevant data from userspace to the vb->planes unconditionally as it's possible some of the fields may have changed after the buffer has been validated. Keep the dma_buf_put(planes[plane].dbuf) calls in the first `if (!reacquired)` case, in order to be close to the plane validation code where the buffers were got in the first place. Cc: stable@vger.kernel.org Fixes: 95af7c0 ("media: videobuf2-core: release all planes first in __prepare_dmabuf()") Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org> Tested-by: Will McVicker <willmcvicker@google.com> Acked-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
1 parent a4aebaf commit 702a47c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/media/common/videobuf2/videobuf2-core.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,18 +1482,23 @@ static int __prepare_dmabuf(struct vb2_buffer *vb)
14821482
}
14831483
vb->planes[plane].dbuf_mapped = 1;
14841484
}
1485+
} else {
1486+
for (plane = 0; plane < vb->num_planes; ++plane)
1487+
dma_buf_put(planes[plane].dbuf);
1488+
}
14851489

1486-
/*
1487-
* Now that everything is in order, copy relevant information
1488-
* provided by userspace.
1489-
*/
1490-
for (plane = 0; plane < vb->num_planes; ++plane) {
1491-
vb->planes[plane].bytesused = planes[plane].bytesused;
1492-
vb->planes[plane].length = planes[plane].length;
1493-
vb->planes[plane].m.fd = planes[plane].m.fd;
1494-
vb->planes[plane].data_offset = planes[plane].data_offset;
1495-
}
1490+
/*
1491+
* Now that everything is in order, copy relevant information
1492+
* provided by userspace.
1493+
*/
1494+
for (plane = 0; plane < vb->num_planes; ++plane) {
1495+
vb->planes[plane].bytesused = planes[plane].bytesused;
1496+
vb->planes[plane].length = planes[plane].length;
1497+
vb->planes[plane].m.fd = planes[plane].m.fd;
1498+
vb->planes[plane].data_offset = planes[plane].data_offset;
1499+
}
14961500

1501+
if (reacquired) {
14971502
/*
14981503
* Call driver-specific initialization on the newly acquired buffer,
14991504
* if provided.
@@ -1503,9 +1508,6 @@ static int __prepare_dmabuf(struct vb2_buffer *vb)
15031508
dprintk(q, 1, "buffer initialization failed\n");
15041509
goto err_put_vb2_buf;
15051510
}
1506-
} else {
1507-
for (plane = 0; plane < vb->num_planes; ++plane)
1508-
dma_buf_put(planes[plane].dbuf);
15091511
}
15101512

15111513
ret = call_vb_qop(vb, buf_prepare, vb);

0 commit comments

Comments
 (0)