Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp708013imm; Wed, 13 Jun 2018 07:08:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLqdLGRiZVVez771P0VIHcNaw2qKM9p1b2IPSawIgvtPHrXzbplYEszocMDwAS0K3ZT2gie X-Received: by 2002:a62:968f:: with SMTP id s15-v6mr5106714pfk.191.1528898911241; Wed, 13 Jun 2018 07:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528898911; cv=none; d=google.com; s=arc-20160816; b=WEkZJyyo5r0C2goZkSLIo1vxkYADDT10aDXsD9VLNDQfKF0M47IUO9JrhUGvYefaUU Xwx/va/rHip64WXhKQH452bojI3DutX0SQqVD4U3QwLgUj2Y5sFh1oM2kdJ4vLzm+CXi CSjhZhZ3V58UF64Q+72e73GBOPJGKhgXSQ60ExOBudcAkXdDKWP8dc/sAKvTpTGIQC9N j7Gm1pmG5Qnv7dORZ/bAAy2D8eoCd8gU1Z3/rKrtDGMr1jm+mopEaG6M5KR1wAJ7xiAv vjON3ls9m9wKt2MMC6Qf+YEppYpZL6dDIE9q0fny1El2v3iE1q6uiXuDUwWMetEX1dZ7 DYiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=m5vpu8Q2kioBF80fxOPxQ/6x/elHYwIEt90CueZLuNo=; b=ftUQPwMaQPBn87oAX7ZwIr/q+/vVr5xgdSwRYHUbXW0ZInYAxgKYFerA3glnm3PB2K jH0NJOfZd8pxFYWpvM0eGFMwAhKOXsuONtoOJ2zLV+JMl+gwJGjzyxrWKn9zyfeFfzhp 2i7e01NvmIauruM8WSyqMkUmj9GRn84mcebZCYg0jCJC/Qj4sLMknv5nUQu5/SzEyT6v 882yuuYvleiAaucb2nfGbW8Dmj4ffZvx+zPBLxfl3/S1d1spRBCQ3YZ/HxQEPjVe67Zm kp/dyLApYcBZbaEb8D6Ok5mUkDJkZMO8jgDLN3jYeh0DKlRQT3BELdsJW/cSIokPYQ2V 2Dwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i69-v6si2433678pge.674.2018.06.13.07.08.16; Wed, 13 Jun 2018 07:08:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935836AbeFMOHX (ORCPT + 99 others); Wed, 13 Jun 2018 10:07:23 -0400 Received: from mail.bootlin.com ([62.4.15.54]:52344 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935769AbeFMOHT (ORCPT ); Wed, 13 Jun 2018 10:07:19 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id D083520981; Wed, 13 Jun 2018 16:07:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 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 Cc: tfiga@chromium.org, posciak@chromium.org, Paul Kocialkowski , Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, nicolas.dufresne@collabora.com, jenskuske@gmail.com, linux-sunxi@googlegroups.com, Thomas Petazzoni , Maxime Ripard 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.0