From patchwork Fri Feb 19 20:00:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Parrot X-Patchwork-Id: 8363561 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2304AC0554 for ; Fri, 19 Feb 2016 20:01:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 311DF2044B for ; Fri, 19 Feb 2016 20:01:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F16E2044C for ; Fri, 19 Feb 2016 20:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757455AbcBSUAs (ORCPT ); Fri, 19 Feb 2016 15:00:48 -0500 Received: from arroyo.ext.ti.com ([192.94.94.40]:44182 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbcBSUAr (ORCPT ); Fri, 19 Feb 2016 15:00:47 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id u1JK0kq9016474; Fri, 19 Feb 2016 14:00:46 -0600 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u1JK0kGm008255; Fri, 19 Feb 2016 14:00:46 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.224.2; Fri, 19 Feb 2016 14:00:46 -0600 Received: from tct7400.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u1JK0kJB027275; Fri, 19 Feb 2016 14:00:46 -0600 From: Benoit Parrot To: Hans Verkuil CC: , Subject: [Patch] media: ti-vpe: cal: Fix warning: variable dereference before being checked Date: Fri, 19 Feb 2016 14:00:30 -0600 Message-ID: <1455912030-28089-1-git-send-email-bparrot@ti.com> X-Mailer: git-send-email 2.7.1.287.g4943984 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As reported ctx->sensor is being dereferenced before being checked in cal_get_external_info(). That being the case it was also checked twice in multiple other location where v4l2_subdev_call is already checking it so no need to explicitly check it again. Reported-by: Dan Carpenter Signed-off-by: Benoit Parrot --- drivers/media/platform/ti-vpe/cal.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c index 76d81b61ecb3..fa714bf1dce1 100644 --- a/drivers/media/platform/ti-vpe/cal.c +++ b/drivers/media/platform/ti-vpe/cal.c @@ -804,6 +804,9 @@ static int cal_get_external_info(struct cal_ctx *ctx) { struct v4l2_ctrl *ctrl; + if (!ctx->sensor) + return -ENODEV; + ctrl = v4l2_ctrl_find(ctx->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE); if (!ctrl) { ctx_err(ctx, "no pixel rate control in subdev: %s\n", @@ -950,9 +953,6 @@ static int __subdev_get_format(struct cal_ctx *ctx, struct v4l2_mbus_framefmt *mbus_fmt = &sd_fmt.format; int ret; - if (!ctx->sensor) - return -EINVAL; - sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; sd_fmt.pad = 0; @@ -975,9 +975,6 @@ static int __subdev_set_format(struct cal_ctx *ctx, struct v4l2_mbus_framefmt *mbus_fmt = &sd_fmt.format; int ret; - if (!ctx->sensor) - return -EINVAL; - sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; sd_fmt.pad = 0; *mbus_fmt = *fmt; @@ -1152,7 +1149,7 @@ static int cal_enum_framesizes(struct file *file, void *fh, ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size, NULL, &fse); if (ret) - return -EINVAL; + return ret; ctx_dbg(1, ctx, "%s: index: %d code: %x W:[%d,%d] H:[%d,%d]\n", __func__, fse.index, fse.code, fse.min_width, fse.max_width, @@ -1331,13 +1328,11 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count) cal_wr_dma_addr(ctx, addr); csi2_ppi_enable(ctx); - if (ctx->sensor) { - if (v4l2_subdev_call(ctx->sensor, video, s_stream, 1)) { - ctx_err(ctx, "stream on failed in subdev\n"); - cal_runtime_put(ctx->dev); - ret = -EINVAL; - goto err; - } + ret = v4l2_subdev_call(ctx->sensor, video, s_stream, 1); + if (ret) { + ctx_err(ctx, "stream on failed in subdev\n"); + cal_runtime_put(ctx->dev); + goto err; } if (debug >= 4) @@ -1360,10 +1355,8 @@ static void cal_stop_streaming(struct vb2_queue *vq) struct cal_buffer *buf, *tmp; unsigned long flags; - if (ctx->sensor) { - if (v4l2_subdev_call(ctx->sensor, video, s_stream, 0)) - ctx_err(ctx, "stream off failed in subdev\n"); - } + if (v4l2_subdev_call(ctx->sensor, video, s_stream, 0)) + ctx_err(ctx, "stream off failed in subdev\n"); csi2_ppi_disable(ctx); disable_irqs(ctx);