From patchwork Thu Jun 21 08:53:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugues FRUCHET X-Patchwork-Id: 10479501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2AB3D60230 for ; Thu, 21 Jun 2018 08:54:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1963B201BC for ; Thu, 21 Jun 2018 08:54:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C6B12916F; Thu, 21 Jun 2018 08:54:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52DD7201BC for ; Thu, 21 Jun 2018 08:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754173AbeFUIyb (ORCPT ); Thu, 21 Jun 2018 04:54:31 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:51327 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754085AbeFUIy3 (ORCPT ); Thu, 21 Jun 2018 04:54:29 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w5L8n3ra001790; Thu, 21 Jun 2018 10:53:51 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2jr4cu17ht-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 21 Jun 2018 10:53:51 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 237F442; Thu, 21 Jun 2018 08:53:50 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A9941263A; Thu, 21 Jun 2018 08:53:50 +0000 (GMT) Received: from SAFEX1HUBCAS23.st.com (10.75.90.47) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 21 Jun 2018 10:53:50 +0200 Received: from localhost (10.201.23.73) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 21 Jun 2018 10:53:50 +0200 From: Hugues Fruchet To: Steve Longerbeam , Sakari Ailus , Hans Verkuil , "Mauro Carvalho Chehab" CC: , Hugues Fruchet , Benjamin Gaignard , Maxime Ripard Subject: [PATCH v4] media: ov5640: fix frame interval enumeration Date: Thu, 21 Jun 2018 10:53:39 +0200 Message-ID: <1529571219-7599-1-git-send-email-hugues.fruchet@st.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.201.23.73] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-21_03:, , signatures=0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Driver must reject frame interval enumeration of unsupported resolution. This was detected by v4l2-compliance format ioctl test: v4l2-compliance Format ioctls: info: found 2 frameintervals for pixel format 4745504a and size 176x144 fail: v4l2-test-formats.cpp(123): found frame intervals for invalid size 177x144 test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL Signed-off-by: Hugues Fruchet --- version 2: - revisit patch according to Mauro comments: See https://www.mail-archive.com/linux-media@vger.kernel.org/msg127380.html version 3: - revisit patch using v4l2_find_nearest_size() helper as per Sakari suggestion: See https://www.mail-archive.com/linux-media@vger.kernel.org/msg128186.html version 4: - fix sparse warning: See https://www.mail-archive.com/linux-media@vger.kernel.org/msg132925.html drivers/media/i2c/ov5640.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index f6e40cc..4257ca6 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -1389,24 +1389,16 @@ static int ov5640_set_timings(struct ov5640_dev *sensor, ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr, int width, int height, bool nearest) { - const struct ov5640_mode_info *mode = NULL; - int i; - - for (i = OV5640_NUM_MODES - 1; i >= 0; i--) { - mode = &ov5640_mode_data[fr][i]; - - if (!mode->reg_data) - continue; + const struct ov5640_mode_info *mode; - if ((nearest && mode->hact <= width && - mode->vact <= height) || - (!nearest && mode->hact == width && - mode->vact == height)) - break; - } + mode = v4l2_find_nearest_size(&ov5640_mode_data[fr][0], + ARRAY_SIZE(ov5640_mode_data[fr]), + hact, vact, + width, height); - if (nearest && i < 0) - mode = &ov5640_mode_data[fr][0]; + if (!mode || + (!nearest && (mode->hact != width || mode->vact != height))) + return NULL; return mode; } @@ -2435,8 +2427,14 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd, sensor->current_fr = frame_rate; sensor->frame_interval = fi->interval; - sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->hact, - mode->vact, true); + mode = ov5640_find_mode(sensor, frame_rate, mode->hact, + mode->vact, true); + if (!mode) { + ret = -EINVAL; + goto out; + } + + sensor->current_mode = mode; sensor->pending_mode_change = true; out: mutex_unlock(&sensor->lock);