Skip to content

Commit 5964c90

Browse files
pinchartlHans Verkuil
authored andcommitted
media: rkisp1: Fix line stride calculation
The line stride is expressed in the hardware as a number of pixels for the first plane. The bytesperline must thus be a multiple of the first plane's bpp value. Enforce this constraint. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Sakari Ailus <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 1f3ba4b commit 5964c90

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,20 @@ rkisp1_fill_pixfmt(struct v4l2_pix_format_mplane *pixm,
11011101
memset(pixm->plane_fmt, 0, sizeof(pixm->plane_fmt));
11021102
info = v4l2_format_info(pixm->pixelformat);
11031103
pixm->num_planes = info->mem_planes;
1104-
stride = info->bpp[0] * pixm->width;
1105-
/* Self path supports custom stride but Main path doesn't */
1106-
if (id == RKISP1_MAINPATH || plane_y->bytesperline < stride)
1107-
plane_y->bytesperline = stride;
1108-
plane_y->sizeimage = plane_y->bytesperline * pixm->height;
11091104

1110-
/* normalize stride to pixels per line */
1111-
stride = DIV_ROUND_UP(plane_y->bytesperline, info->bpp[0]);
1105+
/*
1106+
* The SP supports custom strides, expressed as a number of pixels for
1107+
* the Y plane. Clamp the stride to a reasonable value to avoid integer
1108+
* overflows when calculating the bytesperline and sizeimage values.
1109+
*/
1110+
if (id == RKISP1_SELFPATH)
1111+
stride = clamp(DIV_ROUND_UP(plane_y->bytesperline, info->bpp[0]),
1112+
pixm->width, 65536U);
1113+
else
1114+
stride = pixm->width;
1115+
1116+
plane_y->bytesperline = stride * info->bpp[0];
1117+
plane_y->sizeimage = plane_y->bytesperline * pixm->height;
11121118

11131119
for (i = 1; i < info->comp_planes; i++) {
11141120
struct v4l2_plane_pix_format *plane = &pixm->plane_fmt[i];

0 commit comments

Comments
 (0)