Skip to content

Commit 1d28381

Browse files
andrzejtpgregkh
authored andcommitted
media: cedrus: Fix .buf_prepare
[ Upstream commit d84b920 ] The driver should only set the payload on .buf_prepare if the buffer is CAPTURE type. If an OUTPUT buffer has a zero bytesused set by userspace then v4l2-core will set it to buffer length. If we overwrite bytesused for OUTPUT buffers, too, then vb2_get_plane_payload() will return incorrect value which might be then written to hw registers by the driver in cedrus_h264.c or cedrus_vp8.c. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cbfb77c commit 1d28381

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/staging/media/sunxi/cedrus/cedrus_video.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,13 @@ static int cedrus_buf_prepare(struct vb2_buffer *vb)
449449
if (vb2_plane_size(vb, 0) < pix_fmt->sizeimage)
450450
return -EINVAL;
451451

452-
vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage);
452+
/*
453+
* Buffer's bytesused must be written by driver for CAPTURE buffers.
454+
* (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets
455+
* it to buffer length).
456+
*/
457+
if (V4L2_TYPE_IS_CAPTURE(vq->type))
458+
vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage);
453459

454460
return 0;
455461
}

0 commit comments

Comments
 (0)