From patchwork Tue Jan 5 15:28:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11999385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FC11C433E0 for ; Tue, 5 Jan 2021 15:33:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AAA822AAB for ; Tue, 5 Jan 2021 15:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728118AbhAEPd6 (ORCPT ); Tue, 5 Jan 2021 10:33:58 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:37698 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727887AbhAEPd6 (ORCPT ); Tue, 5 Jan 2021 10:33:58 -0500 Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4B7AB8F9; Tue, 5 Jan 2021 16:29:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1609860592; bh=807i8T4J6QzBj4RJtX/VKgdF5+1MXngInY/cGl56qro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N58tF70Ouu8tH5I2xwoQwbgrYBkDB8iMVLjLCkhTOKZuV8+zVLHwKxrwqw7NHmqR+ Zc6SYephRpn0gP1mjgqDYyZPklO56Dj1g+jGOdSuOTb40EPTRkRh8svO+tmB7LSv5i r2fr+dG1ulxXrnzTKBUltXyCLZxk9SGG4YuRIeUA= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Steve Longerbeam , Philipp Zabel , Ezequiel Garcia Subject: [PATCH 26/75] media: imx: capture: Simplify capture_validate_fmt() implementation Date: Tue, 5 Jan 2021 17:28:03 +0200 Message-Id: <20210105152852.5733-27-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210105152852.5733-1-laurent.pinchart@ideasonboard.com> References: <20210105152852.5733-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org capture_validate_fmt() delegates the media bus format to pixel format conversion to __capture_legacy_try_fmt(). It turns out that this can be simplified quite a lot: - The format lookup from media bus code can be performed by the recently added capture_find_format() function instead of receiving the information from a side effect of __capture_legacy_try_fmt(). - The validation of the pixel format size isn't needed, as they duplicate the validation of the compose rectangle. The pixel format size is directly derived from the size of the incoming stream, which is stored in the compose rectangle. If the compose rectangle is valid, the pixel format size will be valid too. By removing the validation of the pixel format size and using capture_find_format() to lookup the format, we can stop using __capture_legacy_try_fmt() and simplify capture_validate_fmt(). Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-capture.c | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index 775ebce92c94..8f3c0da371d3 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -537,27 +537,35 @@ static int capture_validate_fmt(struct capture_priv *priv) { struct v4l2_subdev_format fmt_src; const struct imx_media_pixfmt *cc; - struct v4l2_rect compose; - struct v4l2_pix_format pixfmt; int ret; + /* Retrieve the media bus format on the source subdev. */ fmt_src.pad = priv->src_sd_pad; fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE; ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src); if (ret) return ret; - v4l2_fill_pix_format(&pixfmt, &fmt_src.format); + /* + * Verify that the media bus size matches the size set on the video + * node. It is sufficient to check the compose rectangle size without + * checking the rounded size from vdev.fmt, as the rounded size is + * derived directly from the compose rectangle size, and will thus + * always match if the compose rectangle matches. + */ + if (priv->vdev.compose.width != fmt_src.format.width || + priv->vdev.compose.height != fmt_src.format.height) + return -EPIPE; - ret = __capture_legacy_try_fmt(priv, &fmt_src, &pixfmt, &cc, &compose); - if (ret) - return ret; + /* + * Verify that the media bus code is compatible with the pixel format + * set on the video node. + */ + cc = capture_find_format(fmt_src.format.code, 0); + if (!cc || priv->vdev.cc->cs != cc->cs) + return -EPIPE; - return (priv->vdev.fmt.width != pixfmt.width || - priv->vdev.fmt.height != pixfmt.height || - priv->vdev.cc->cs != cc->cs || - priv->vdev.compose.width != compose.width || - priv->vdev.compose.height != compose.height) ? -EPIPE : 0; + return 0; } static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)