Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1784208imm; Thu, 21 Jun 2018 02:16:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKpDkbKhXULsVdb23/6qN1CmS2Wa+zLvvydjPLtShLZUI9rI9F6aa031uZhir2TPLjKkDL+ X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr27273390pld.72.1529572568195; Thu, 21 Jun 2018 02:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529572568; cv=none; d=google.com; s=arc-20160816; b=FxsyNsyzbiXuxfI6I+EJ9rub8uPHiQ6mzVghYvPrw1bYzRDMXe5Xl8IH7Aw466c002 bFxW+kgM/OJmj3RJqTPRhCqSgrxAT9qYAsn7oDVoEqWXLX/+hn6jxIydQawSOEaDgUPs 7F5SGEIJgtFo6tJy3CeijbKXg0Zrfab0Dm1nz5IwkbRy59b5TZghYStazO0iDl/WIcIi RcXGwkxZCToailLtO3Y2Xyb1desRR7Eo6XA5B8MxNcubnN0rW5PVT3w/lRgaFKf+lX7n F0KJf54JcVGuWgvivQcx99C4ESQ2zrrLmm591GdQ1TL+DlE+V0+BUYYFt9XKF7CiiibN gH0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:references :in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=Fmf8jifDUkTkN7HX7yIPh8ad50mLypm6BAVzn0LCbz0=; b=HZm1v5vYp+AP6MZNyieYtGeUvA2+1cTaT2diDI8EcaR6nghskty5RpdE5e3V+fywBb 9oRtjscb/wkTp9RgMnI4Z1qfI3/f7oS2DwTuwlVCsVuzvu8cdvTAxQBpxfbNwxPMRVCO xkmBl7JKiyCkWvEMDdvCIWgxBXnQ08wTnKxU+NwzydYYbQjuU8kIjgeG0tSVotX4nFCJ MYPCUjapzR02UFVirSC1i3L3S8rphJwKfGuaNb2XlDaQUvj2s201XEzAIg8uaIvUynn4 DtQ6HIVkX9CxrLc5fbkvIzXAciEtdt0rFT2hS1NBpFmasUKCSl8ZooMgVHnD2Hyu4Uh7 jJpA== 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 d34-v6si4349104pld.252.2018.06.21.02.15.53; Thu, 21 Jun 2018 02:16:08 -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 S932798AbeFUJNd (ORCPT + 99 others); Thu, 21 Jun 2018 05:13:33 -0400 Received: from mail.bootlin.com ([62.4.15.54]:47746 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932482AbeFUJNb (ORCPT ); Thu, 21 Jun 2018 05:13:31 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 7ED84206D8; Thu, 21 Jun 2018 11:13:29 +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 aptenodytes (AAubervilliers-681-1-50-153.w90-88.abo.wanadoo.fr [90.88.168.153]) by mail.bootlin.com (Postfix) with ESMTPSA id 1EFB9203D9; Thu, 21 Jun 2018 11:13:19 +0200 (CEST) Message-ID: <18ffd09bf91908886aebbad127e612775b7f0bf8.camel@bootlin.com> Subject: Re: [PATCH 3/9] media: cedrus: Add a macro to check for the validity of a control From: Paul Kocialkowski To: Maxime Ripard , hans.verkuil@cisco.com, acourbot@chromium.org, sakari.ailus@linux.intel.com, Laurent Pinchart Cc: tfiga@chromium.org, posciak@chromium.org, 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 Date: Thu, 21 Jun 2018 11:13:19 +0200 In-Reply-To: <20180613140714.1686-4-maxime.ripard@bootlin.com> References: <20180613140714.1686-1-maxime.ripard@bootlin.com> <20180613140714.1686-4-maxime.ripard@bootlin.com> Organization: Bootlin Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-VQE9UU1GTYaO8ZSYHoUI" X-Mailer: Evolution 3.28.2 Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-VQE9UU1GTYaO8ZSYHoUI Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > 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. >=20 > 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. >=20 > Add a macro that expands to the proper check in order to reduce the > duplication. >=20 > Signed-off-by: Maxime Ripard > --- > .../platform/sunxi/cedrus/sunxi_cedrus_dec.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) >=20 > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_dec.c b/dri= vers/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) > =20 > spin_lock_irqsave(&ctx->dev->irq_lock, flags); > =20 > +#define CHECK_CONTROL(ctx, ctrl) \ > + if (!ctx->ctrls[(ctrl)]) { \ Although this was not introduced in this patch, I believe this approach won't work since ctx->ctrls[i] is a pointer returned from v4l2_ctrl_new_custom(hdl, &cfg, NULL), which will always be non-null after calling cedrus_init_ctrls. Perhaps checking ctx->ctrls[i].p_cur.p would be the right thing to check, but I'm unsure about that. > + v4l2_err(&(ctx)->dev->v4l2_dev, "Invalid " #ctrl " control\n"); \ > + (ctx)->job_abort =3D 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 =3D 1; > - goto unlock_complete; > - } > - > + CHECK_CONTROL(ctx, SUNXI_CEDRUS_CTRL_DEC_MPEG2_FRAME_HDR); > run.mpeg2.hdr =3D get_ctrl_ptr(ctx, SUNXI_CEDRUS_CTRL_DEC_MPEG2_FRAME_= HDR); > sunxi_cedrus_mpeg2_setup(ctx, &run); > =20 > @@ -128,6 +129,7 @@ void sunxi_cedrus_device_run(void *priv) > default: > ctx->job_abort =3D 1; > } Maybe add a newline here? Cheers, Paul > +#undef CHECK_CONTROL > =20 > unlock_complete: > spin_unlock_irqrestore(&ctx->dev->irq_lock, flags); --=20 Paul Kocialkowski, Bootlin (formerly Free Electrons) Embedded Linux and kernel engineering https://bootlin.com --=-VQE9UU1GTYaO8ZSYHoUI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEJZpWjZeIetVBefti3cLmz3+fv9EFAlsrbC8ACgkQ3cLmz3+f v9FWTwgAlcGN1gPoncx1y38kxL7Z7K0/XVu2lLjn2+n2fSHP6WJj+QtBUuQEfa1y IX+/UBeXFrZvx49GH9A9fmXsbGRME56ocRDLR4koNopdaQrWdbgNx6NACEUgEK3A zWimSjS18/qJj6js1OyRVsnZpU7hfuL7yfTt5e9a03ybYPQ7BtVfJsh0MXSxyDur z6evE9taF3d37tMkCuf81y7l5qlvbKu1menzn9CT9+M5HbUDysdpDcuMOBdnmLXd +zICme6Abs7UZfPE6sEMSBPkAUwpG4/M8LrfOF7lUGOZ3RZ9K9XwcUhQeeMfjeXH BHvWvyDJEzmMAtszIlu6eVArR+KsgA== =uWyX -----END PGP SIGNATURE----- --=-VQE9UU1GTYaO8ZSYHoUI--