[media] V4L: mx2_camera: .try_fmt shouldn't fail

If the user is requesting too large a frame, instead of failing
select an acceptable geometry, preserving the requested aspect ratio.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Guennadi Liakhovetski 2011-06-04 15:06:47 -03:00 committed by Mauro Carvalho Chehab
parent 497833c681
commit 28281a71eb

View File

@ -973,11 +973,16 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
if (pix->bytesperline < 0) if (pix->bytesperline < 0)
return pix->bytesperline; return pix->bytesperline;
pix->sizeimage = pix->height * pix->bytesperline; pix->sizeimage = pix->height * pix->bytesperline;
if (pix->sizeimage > (4 * 0x3ffff)) { /* CSIRXCNT limit */ /* Check against the CSIRXCNT limit */
dev_warn(icd->dev.parent, if (pix->sizeimage > 4 * 0x3ffff) {
"Image size (%u) above limit\n", /* Adjust geometry, preserve aspect ratio */
pix->sizeimage); unsigned int new_height = int_sqrt(4 * 0x3ffff *
return -EINVAL; pix->height / pix->bytesperline);
pix->width = new_height * pix->width / pix->height;
pix->height = new_height;
pix->bytesperline = soc_mbus_bytes_per_line(pix->width,
xlate->host_fmt);
BUG_ON(pix->bytesperline < 0);
} }
} }