From patchwork Wed Jun 13 14:07:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10462297 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 45B55603B4 for ; Wed, 13 Jun 2018 14:07:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F81026246 for ; Wed, 13 Jun 2018 14:07:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2361928614; Wed, 13 Jun 2018 14:07:48 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C95226246 for ; Wed, 13 Jun 2018 14:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5+XMMybcRcjdVZR17ZXOEfs//yVtGFJ/Y4Z7bXQ550w=; b=hRMB63C3GoyVkotq0qalZK3T15 3bCXvAzc8CrZhDMITUfNc4Kaoj8PxVrdw92Tq7Rlc2w4dmQBL0iyM9VIXwoxmGnEmP/wCfypQnpg/ VQuPlQJWIpLIfOK8I0aITwZWMh+nLZwEU+vjrPjCgIKxMAm7Xp0xeqB+5vivqGyXsGHLTrWtPcJaM t3u2RcyAmfsz+BcTK4JflRspp+imGdnKxDMT8OGq0kEDGb2aWaOGmXrXw+iXKye1p9+CCw01M2ilC R1ZA/NLUOjcAAGO3IjxgfA2dKXsUM5CzEZw7H7+5xTFaLabKMZfp2f7qZmIWebzkHkOpZLyYrebIn y5mbO1sQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT6Qz-0007dX-0y; Wed, 13 Jun 2018 14:07:37 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT6Qs-0007W7-OB for linux-arm-kernel@lists.infradead.org; Wed, 13 Jun 2018 14:07:34 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id D083520981; Wed, 13 Jun 2018 16:07:17 +0200 (CEST) Received: from localhost (AAubervilliers-681-1-37-30.w90-88.abo.wanadoo.fr [90.88.156.30]) by mail.bootlin.com (Postfix) with ESMTPSA id A412D203B4; Wed, 13 Jun 2018 16:07:17 +0200 (CEST) From: Maxime Ripard To: hans.verkuil@cisco.com, acourbot@chromium.org, sakari.ailus@linux.intel.com, Laurent Pinchart Subject: [PATCH 3/9] media: cedrus: Add a macro to check for the validity of a control Date: Wed, 13 Jun 2018 16:07:08 +0200 Message-Id: <20180613140714.1686-4-maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180613140714.1686-1-maxime.ripard@bootlin.com> References: <20180613140714.1686-1-maxime.ripard@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_070730_951242_5B81C91B X-CRM114-Status: GOOD ( 10.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , jenskuske@gmail.com, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, tfiga@chromium.org, Paul Kocialkowski , Chen-Yu Tsai , posciak@chromium.org, Thomas Petazzoni , nicolas.dufresne@collabora.com, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP During our frame decoding setup, we need to check a number of controls to make sure that they are properly filled before trying to access them. It's not too bad with MPEG2 since there's just a single one, but with the upcoming increase of codecs, and the integration of more complex codecs, this logic will be duplicated a significant number of times. H264 for example uses 4 different controls. Add a macro that expands to the proper check in order to reduce the duplication. Signed-off-by: Maxime Ripard --- .../platform/sunxi/cedrus/sunxi_cedrus_dec.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_dec.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_dec.c index 8c92af34ebeb..c19acf9626c4 100644 --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_dec.c +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_dec.c @@ -110,15 +110,16 @@ void sunxi_cedrus_device_run(void *priv) spin_lock_irqsave(&ctx->dev->irq_lock, flags); +#define CHECK_CONTROL(ctx, ctrl) \ + if (!ctx->ctrls[(ctrl)]) { \ + v4l2_err(&(ctx)->dev->v4l2_dev, "Invalid " #ctrl " control\n"); \ + (ctx)->job_abort = 1; \ + goto unlock_complete; \ + } + switch (ctx->vpu_src_fmt->fourcc) { case V4L2_PIX_FMT_MPEG2_FRAME: - if (!ctx->ctrls[SUNXI_CEDRUS_CTRL_DEC_MPEG2_FRAME_HDR]) { - v4l2_err(&ctx->dev->v4l2_dev, - "Invalid MPEG2 frame header control\n"); - ctx->job_abort = 1; - goto unlock_complete; - } - + CHECK_CONTROL(ctx, SUNXI_CEDRUS_CTRL_DEC_MPEG2_FRAME_HDR); run.mpeg2.hdr = get_ctrl_ptr(ctx, SUNXI_CEDRUS_CTRL_DEC_MPEG2_FRAME_HDR); sunxi_cedrus_mpeg2_setup(ctx, &run); @@ -128,6 +129,7 @@ void sunxi_cedrus_device_run(void *priv) default: ctx->job_abort = 1; } +#undef CHECK_CONTROL unlock_complete: spin_unlock_irqrestore(&ctx->dev->irq_lock, flags);