]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: ti-vpe: vpe: fix a v4l2-compliance failure about invalid sizeimage
authorBenoit Parrot <bparrot@ti.com>
Mon, 7 Oct 2019 15:09:59 +0000 (12:09 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 15:44:03 +0000 (16:44 +0100)
[ Upstream commit 0bac73adea4df8d34048b38f6ff24dc3e73e90b6 ]

v4l2-compliance fails with this message:

   fail: v4l2-test-formats.cpp(463): !pfmt.sizeimage
   fail: v4l2-test-formats.cpp(736): \
Video Capture Multiplanar is valid, \
but TRY_FMT failed to return a format
   test VIDIOC_TRY_FMT: FAIL

This failure is causd by the driver failing to handle out range
'bytesperline' values from user space applications.

VPDMA hardware is limited to 64k line stride (16 bytes aligned, so 65520
bytes). So make sure the provided or calculated 'bytesperline' is
smaller than the maximum value.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/ti-vpe/vpdma.h
drivers/media/platform/ti-vpe/vpe.c

index 28bc9412934848988b42c8a7c95dc38a08b49e83..9bacfd60325017efdd7c53ff009bb3f498df072b 100644 (file)
@@ -57,6 +57,7 @@ struct vpdma_data_format {
                                                 * line stride of source and dest
                                                 * buffers should be 16 byte aligned
                                                 */
+#define VPDMA_MAX_STRIDE               65520   /* Max line stride 16 byte aligned */
 #define VPDMA_DTD_DESC_SIZE            32      /* 8 words */
 #define VPDMA_CFD_CTD_DESC_SIZE                16      /* 4 words */
 
index 512660b4ee6362c3f30eb0a63369950ae1d31188..8b14ba4a3d9eaa9029663a030955833534c63b3c 100644 (file)
@@ -1668,6 +1668,10 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
                if (stride > plane_fmt->bytesperline)
                        plane_fmt->bytesperline = stride;
 
+               plane_fmt->bytesperline = clamp_t(u32, plane_fmt->bytesperline,
+                                                 stride,
+                                                 VPDMA_MAX_STRIDE);
+
                plane_fmt->bytesperline = ALIGN(plane_fmt->bytesperline,
                                                VPDMA_STRIDE_ALIGN);