From patchwork Mon Jun 6 17:12:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 852812 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p56HCddY008389 for ; Mon, 6 Jun 2011 17:12:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756167Ab1FFRMh (ORCPT ); Mon, 6 Jun 2011 13:12:37 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:54204 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751596Ab1FFRMh (ORCPT ); Mon, 6 Jun 2011 13:12:37 -0400 Received: from axis700.grange (dslb-178-006-245-001.pools.arcor-ip.net [178.6.245.1]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0M1kWE-1PbNnq3tvu-00trhp; Mon, 06 Jun 2011 19:12:29 +0200 Received: by axis700.grange (Postfix, from userid 1000) id 79077189B78; Mon, 6 Jun 2011 19:12:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 6F42D189B77; Mon, 6 Jun 2011 19:12:28 +0200 (CEST) Date: Mon, 6 Jun 2011 19:12:28 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List cc: Baruch Siach , Sascha Hauer Subject: [PATCH] V4L: mx2_camera: .try_fmt shouldn't fail Message-ID: MIME-Version: 1.0 X-Provags-ID: V02:K0:MWBmtcQVrvb7tEXzW84IhQZQcmT0m0VXuB+t9LZJmUw Cnw0Rcogtby1Ef+B08Oz3Ox3PBRuZyb76LwYDyfb4EaqYNvVqk DlNSEUGABT+Ta7XI7JySoVUeuLrSvKTghBZPzkwxUHd32xIlkY b9JVm6KPcz2edxPN4hDkAZxhlh8MSQmAd28fSlbrc4MfMd+ysn hQIXGLG1OKiU2vahxQxLBoAPpXoedBw9F7XBUnw7YM= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 06 Jun 2011 17:12:39 +0000 (UTC) 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 --- Attention: completely untested! Please, give it a spin on an i.MX25, specifically, please, try to force a TRY_FMT with too large a frame to test this path. Maybe you'll need to use some debugging printk(). drivers/media/video/mx2_camera.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c index 4eab1c6..8e073a3 100644 --- a/drivers/media/video/mx2_camera.c +++ b/drivers/media/video/mx2_camera.c @@ -974,11 +974,16 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd, if (pix->bytesperline < 0) return pix->bytesperline; pix->sizeimage = pix->height * pix->bytesperline; - if (pix->sizeimage > (4 * 0x3ffff)) { /* CSIRXCNT limit */ - dev_warn(icd->dev.parent, - "Image size (%u) above limit\n", - pix->sizeimage); - return -EINVAL; + /* Check against the CSIRXCNT limit */ + if (pix->sizeimage > 4 * 0x3ffff) { + /* Adjust geometry, preserve aspect ratio */ + unsigned int new_height = int_sqrt(4 * 0x3ffff * + 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); } }