From patchwork Wed Jun 28 20:13:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 106578 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp319551qge; Wed, 28 Jun 2017 13:15:06 -0700 (PDT) X-Received: by 10.84.193.129 with SMTP id f1mr13951229pld.129.1498680906569; Wed, 28 Jun 2017 13:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498680906; cv=none; d=google.com; s=arc-20160816; b=DSVprdXh5lIKZvvU1+xE5v1Gq+aSQKgkTBpUYRyFofyfZ1q2Rkm9w5a8m9m2KPlc/h U7UxNR+0nufaSLsrI7M7lAHYEYfuYL9w7NIIpAo2eN+NzpqCnklUFOe7psviqFWDcam5 HoRiWbpZkuBlXc2yJSec1utI0IRdM0hYQEjgygMqCMIbHByJTOkEi6EFBSd2nXR+XeF0 kDTPTq3q6PMtjZXX0AW2R64ybWpK+RNoDYWgOK+Uyxz+210EDfMIt3+CnbN0wEWPAFgQ eyUKpjMTwZQWcobwpGARUzqt3v8eONNxpteXWHzdciHUyd6vh6yKjCEWhi4fbWi9UmQ6 ujDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4ZuUst2KaPbNilIbfruVplkJYTbLlJYNRNsipl/N1r0=; b=hWQqaGVhnwYBE8b1K62Rs53qam0vjurrfmXb+9Z3ksYHBNXzVXoLbHXTh39JYd9ktU FXMk2xVZEc2jSxxIJYSS8AHgovBVbxGPjTUnLlho8ewvdYqTWeRQ+QhX0WvTyKconrfO qcYnQnv6YNk3+GSqciO1blfqZVE1HOs1QHwp8e5IsfV6Sgp04k6CoQbwjM5T3UOqka80 HxP2B6hoNdkNtZwW+mvTGv+rg0qWVTFAKcQHsY61pRoGXxyMYE3/sPVhxtQJhme3MV5A KGQLVf48CHNeU83pHqHJStiTGGyLsE7lGLW+zdZR5KgXq5Y+/lcGGltxul3ZeQv6Vy5w zb1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-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 i23si2242679pfa.178.2017.06.28.13.15.06; Wed, 28 Jun 2017 13:15:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-media-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-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751986AbdF1UPE (ORCPT + 4 others); Wed, 28 Jun 2017 16:15:04 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:57479 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751557AbdF1UPB (ORCPT ); Wed, 28 Jun 2017 16:15:01 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0Mb2OB-1dBnRU3EoF-00KhZ1; Wed, 28 Jun 2017 22:14:39 +0200 From: Arnd Bergmann To: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab Cc: Arnd Bergmann , Greg Kroah-Hartman , Hans Verkuil , Marek Vasut , Russell King , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] [media] staging/imx: remove confusing IS_ERR_OR_NULL usage Date: Wed, 28 Jun 2017 22:13:25 +0200 Message-Id: <20170628201435.3237712-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:ec836dNvpnNrQX6UDwlL1rjMd6A8qY/CEA7sAck/3DpuITjUqV6 RSpFZKpt1RecaXSIAuSL7SduTNUtx+elIJlOjP8jTKBS4jH5I2X+Q5mEXLDzqEm8nkwxUX3 8jfEtIWz0VPGpHD9QF1SKWZfPyhOZyTYOOUED9u07/vE2Hes7ZdOAjfSVNN+Qtc3zux/8cr FLJU0/9xM5FZLo6cPg8hQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:mmQeCCY+FUI=:0S0fxjmY3hMkvGd5HhnG/V zV2cJZU2z2VoBPdZmVsIQ0/cDeN5xlsAUJxRFCnq8t1VlgVS7pYIs/z7n+cxQsuxwN0oJvIfx PYVvCRVwD7UaDOxRz/cbOhAeKPWinga+5Y4zwe0y6dyKHweRxarKT4PZPNVLe7ROe4HLRi++a SF6g/A/i3NGk1luDNO72OYzM6ZcDKNqCbViRZhx4BRaFuoWARCB/TgyP831LQ5M0ZblhQdSCZ ciL1xvCU/0qhlvk2ZFMTvozMBFQqwW/kBVTrtMqXg6Y8hOgWzjJs6VqbfM6aVJF2lPgJ/pD3J 73cyuqgKa3kIDodau8NZO1sH2OvLOuz/jY4Y8E8c6oqfEl61cv2CBiM2ttyN7aTqTDZP2GnY1 XJSg5/b4uW9YCZi4kjGBdTkr4ctCvlxehVOchqzvfgryJ/TqHuxwLkQrlJj41/tLUdzD/0u5Q IhrrUThBR1LAfOgVWO9p6JzEIvAaaoKngRVgqzsCpFHnEgMFWaunIpP6djIZjQ396ybz44ctx Uyi0my4SETadGveeI8s6gkRH9if4tQSaYg1tAQS9l9Te3uSGeBeK6N4gYcfl3zeH7Vdmd7bnk 8r2SgrYW12q/PQWYgnYziNHvtg5j20wd0Jhz8ca7XsuFfXnbUVP9HCBchWES+08TgiwUTFyHJ y+psCAqzVl8+ABf4FSwZdOws3YaNQUXNre/K35a8O416ATUn3lho01JOCZKz9t+3NbHQ= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org While looking at a compiler warning, I noticed the use of IS_ERR_OR_NULL, which is generally a sign of a bad API design and should be avoided. In this driver, this is fairly easy, we can simply stop storing error pointers in persistent structures, and change the one function that might return either a NULL pointer or an error code to consistently return error pointers when failing. Fixes: e130291212df ("[media] media: Add i.MX media core driver") Signed-off-by: Arnd Bergmann --- I can't reproduce the original warning any more, but this patch still makes sense by itself. --- drivers/staging/media/imx/imx-ic-prpencvf.c | 41 ++++++++++++++++------------- drivers/staging/media/imx/imx-media-csi.c | 29 +++++++++++--------- drivers/staging/media/imx/imx-media-dev.c | 2 +- drivers/staging/media/imx/imx-media-of.c | 2 +- drivers/staging/media/imx/imx-media-vdic.c | 37 ++++++++++++++------------ 5 files changed, 61 insertions(+), 50 deletions(-) -- 2.9.0 Reviewed-by: Philipp Zabel Tested-by: Philipp Zabel diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index ed363fe3b3d0..7a9d9f32f989 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -134,19 +134,19 @@ static inline struct prp_priv *sd_to_priv(struct v4l2_subdev *sd) static void prp_put_ipu_resources(struct prp_priv *priv) { - if (!IS_ERR_OR_NULL(priv->ic)) + if (priv->ic) ipu_ic_put(priv->ic); priv->ic = NULL; - if (!IS_ERR_OR_NULL(priv->out_ch)) + if (priv->out_ch) ipu_idmac_put(priv->out_ch); priv->out_ch = NULL; - if (!IS_ERR_OR_NULL(priv->rot_in_ch)) + if (priv->rot_in_ch) ipu_idmac_put(priv->rot_in_ch); priv->rot_in_ch = NULL; - if (!IS_ERR_OR_NULL(priv->rot_out_ch)) + if (priv->rot_out_ch) ipu_idmac_put(priv->rot_out_ch); priv->rot_out_ch = NULL; } @@ -154,43 +154,46 @@ static void prp_put_ipu_resources(struct prp_priv *priv) static int prp_get_ipu_resources(struct prp_priv *priv) { struct imx_ic_priv *ic_priv = priv->ic_priv; + struct ipu_ic *ic; + struct ipuv3_channel *out_ch, *rot_in_ch, *rot_out_ch; int ret, task = ic_priv->task_id; priv->ipu = priv->md->ipu[ic_priv->ipu_id]; - priv->ic = ipu_ic_get(priv->ipu, task); - if (IS_ERR(priv->ic)) { + ic = ipu_ic_get(priv->ipu, task); + if (IS_ERR(ic)) { v4l2_err(&ic_priv->sd, "failed to get IC\n"); - ret = PTR_ERR(priv->ic); + ret = PTR_ERR(ic); goto out; } + priv->ic = ic; - priv->out_ch = ipu_idmac_get(priv->ipu, - prp_channel[task].out_ch); - if (IS_ERR(priv->out_ch)) { + out_ch = ipu_idmac_get(priv->ipu, prp_channel[task].out_ch); + if (IS_ERR(out_ch)) { v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", prp_channel[task].out_ch); - ret = PTR_ERR(priv->out_ch); + ret = PTR_ERR(out_ch); goto out; } + priv->out_ch = out_ch; - priv->rot_in_ch = ipu_idmac_get(priv->ipu, - prp_channel[task].rot_in_ch); - if (IS_ERR(priv->rot_in_ch)) { + rot_in_ch = ipu_idmac_get(priv->ipu, prp_channel[task].rot_in_ch); + if (IS_ERR(rot_in_ch)) { v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", prp_channel[task].rot_in_ch); - ret = PTR_ERR(priv->rot_in_ch); + ret = PTR_ERR(rot_in_ch); goto out; } + priv->rot_in_ch = rot_in_ch; - priv->rot_out_ch = ipu_idmac_get(priv->ipu, - prp_channel[task].rot_out_ch); - if (IS_ERR(priv->rot_out_ch)) { + rot_out_ch = ipu_idmac_get(priv->ipu, prp_channel[task].rot_out_ch); + if (IS_ERR(rot_out_ch)) { v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", prp_channel[task].rot_out_ch); - ret = PTR_ERR(priv->rot_out_ch); + ret = PTR_ERR(rot_out_ch); goto out; } + priv->rot_out_ch = rot_out_ch; return 0; out: diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index a2d26693912e..a4b3c305dcc8 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -122,11 +122,11 @@ static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev) static void csi_idmac_put_ipu_resources(struct csi_priv *priv) { - if (!IS_ERR_OR_NULL(priv->idmac_ch)) + if (priv->idmac_ch) ipu_idmac_put(priv->idmac_ch); priv->idmac_ch = NULL; - if (!IS_ERR_OR_NULL(priv->smfc)) + if (priv->smfc) ipu_smfc_put(priv->smfc); priv->smfc = NULL; } @@ -134,23 +134,26 @@ static void csi_idmac_put_ipu_resources(struct csi_priv *priv) static int csi_idmac_get_ipu_resources(struct csi_priv *priv) { int ch_num, ret; + struct ipu_smfc *smfc, *idmac_ch; ch_num = IPUV3_CHANNEL_CSI0 + priv->smfc_id; - priv->smfc = ipu_smfc_get(priv->ipu, ch_num); - if (IS_ERR(priv->smfc)) { + smfc = ipu_smfc_get(priv->ipu, ch_num); + if (IS_ERR(smfc)) { v4l2_err(&priv->sd, "failed to get SMFC\n"); - ret = PTR_ERR(priv->smfc); + ret = PTR_ERR(smfc); goto out; } + priv->smfc = smfc; - priv->idmac_ch = ipu_idmac_get(priv->ipu, ch_num); - if (IS_ERR(priv->idmac_ch)) { + idmac_ch = ipu_idmac_get(priv->ipu, ch_num); + if (IS_ERR(idmac_ch)) { v4l2_err(&priv->sd, "could not get IDMAC channel %u\n", ch_num); - ret = PTR_ERR(priv->idmac_ch); + ret = PTR_ERR(idmac_ch); goto out; } + priv->idmac_ch = idmac_ch; return 0; out: @@ -1583,6 +1586,7 @@ static int csi_unsubscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, static int csi_registered(struct v4l2_subdev *sd) { struct csi_priv *priv = v4l2_get_subdevdata(sd); + struct ipu_csi *csi; int i, ret; u32 code; @@ -1590,11 +1594,12 @@ static int csi_registered(struct v4l2_subdev *sd) priv->md = dev_get_drvdata(sd->v4l2_dev->dev); /* get handle to IPU CSI */ - priv->csi = ipu_csi_get(priv->ipu, priv->csi_id); - if (IS_ERR(priv->csi)) { + csi = ipu_csi_get(priv->ipu, priv->csi_id); + if (IS_ERR(csi)) { v4l2_err(&priv->sd, "failed to get CSI%d\n", priv->csi_id); - return PTR_ERR(priv->csi); + return PTR_ERR(csi); } + priv->csi = csi; for (i = 0; i < CSI_NUM_PADS; i++) { priv->pad[i].flags = (i == CSI_SINK_PAD) ? @@ -1663,7 +1668,7 @@ static void csi_unregistered(struct v4l2_subdev *sd) if (priv->fim) imx_media_fim_free(priv->fim); - if (!IS_ERR_OR_NULL(priv->csi)) + if (priv->csi) ipu_csi_put(priv->csi); } diff --git a/drivers/staging/media/imx/imx-media-dev.c b/drivers/staging/media/imx/imx-media-dev.c index 48cbc7716758..c58ff0831890 100644 --- a/drivers/staging/media/imx/imx-media-dev.c +++ b/drivers/staging/media/imx/imx-media-dev.c @@ -91,7 +91,7 @@ imx_media_add_async_subdev(struct imx_media_dev *imxmd, if (imx_media_find_async_subdev(imxmd, np, devname)) { dev_dbg(imxmd->md.dev, "%s: already added %s\n", __func__, np ? np->name : devname); - imxsd = NULL; + imxsd = ERR_PTR(-EEXIST); goto out; } diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index b026fe66467c..4aac42cb79a4 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -115,7 +115,7 @@ of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np, /* register this subdev with async notifier */ imxsd = imx_media_add_async_subdev(imxmd, sd_np, NULL); - if (IS_ERR_OR_NULL(imxsd)) + if (IS_ERR(imxsd)) return imxsd; if (is_csi_port) { diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 7eabdc4aa79f..433474d58e3e 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -126,15 +126,15 @@ struct vdic_priv { static void vdic_put_ipu_resources(struct vdic_priv *priv) { - if (!IS_ERR_OR_NULL(priv->vdi_in_ch_p)) + if (priv->vdi_in_ch_p) ipu_idmac_put(priv->vdi_in_ch_p); priv->vdi_in_ch_p = NULL; - if (!IS_ERR_OR_NULL(priv->vdi_in_ch)) + if (priv->vdi_in_ch) ipu_idmac_put(priv->vdi_in_ch); priv->vdi_in_ch = NULL; - if (!IS_ERR_OR_NULL(priv->vdi_in_ch_n)) + if (priv->vdi_in_ch_n) ipu_idmac_put(priv->vdi_in_ch_n); priv->vdi_in_ch_n = NULL; @@ -146,40 +146,43 @@ static void vdic_put_ipu_resources(struct vdic_priv *priv) static int vdic_get_ipu_resources(struct vdic_priv *priv) { int ret, err_chan; + struct ipuv3_channel *ch; + struct ipu_vdi *vdi; priv->ipu = priv->md->ipu[priv->ipu_id]; - priv->vdi = ipu_vdi_get(priv->ipu); - if (IS_ERR(priv->vdi)) { + vdi = ipu_vdi_get(priv->ipu); + if (IS_ERR(vdi)) { v4l2_err(&priv->sd, "failed to get VDIC\n"); - ret = PTR_ERR(priv->vdi); + ret = PTR_ERR(vdi); goto out; } + priv->vdi = vdi; if (!priv->csi_direct) { - priv->vdi_in_ch_p = ipu_idmac_get(priv->ipu, - IPUV3_CHANNEL_MEM_VDI_PREV); - if (IS_ERR(priv->vdi_in_ch_p)) { + ch = ipu_idmac_get(priv->ipu, IPUV3_CHANNEL_MEM_VDI_PREV); + if (IS_ERR(ch)) { err_chan = IPUV3_CHANNEL_MEM_VDI_PREV; - ret = PTR_ERR(priv->vdi_in_ch_p); + ret = PTR_ERR(ch); goto out_err_chan; } + priv->vdi_in_ch_p = ch; - priv->vdi_in_ch = ipu_idmac_get(priv->ipu, - IPUV3_CHANNEL_MEM_VDI_CUR); - if (IS_ERR(priv->vdi_in_ch)) { + ch = ipu_idmac_get(priv->ipu, IPUV3_CHANNEL_MEM_VDI_CUR); + if (IS_ERR(ch)) { err_chan = IPUV3_CHANNEL_MEM_VDI_CUR; - ret = PTR_ERR(priv->vdi_in_ch); + ret = PTR_ERR(ch); goto out_err_chan; } + priv->vdi_in_ch = ch; - priv->vdi_in_ch_n = ipu_idmac_get(priv->ipu, - IPUV3_CHANNEL_MEM_VDI_NEXT); + ch = ipu_idmac_get(priv->ipu, IPUV3_CHANNEL_MEM_VDI_NEXT); if (IS_ERR(priv->vdi_in_ch_n)) { err_chan = IPUV3_CHANNEL_MEM_VDI_NEXT; - ret = PTR_ERR(priv->vdi_in_ch_n); + ret = PTR_ERR(ch); goto out_err_chan; } + priv->vdi_in_ch_n = ch; } return 0;