Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E561768 for ; Wed, 1 Dec 2021 14:24:44 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id u80so24610412pfc.9 for ; Wed, 01 Dec 2021 06:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+nqjIwk41+U9tH9eGUNa4mmueteq5RxG7HgTGB7HKEw=; b=HRVy0Wi/A0TE+Qh4oMjxWCoWKpQGZrhJrwtLf3lCRLWtxw7zazcBWCI06PUQER51u8 B1sBrqfdc6icul15x5SAyP3YZ3ci45+7BJ4D3+pT+VKrnOXRYq/yzz+lU5DT6I7rVY4y Jzcei8vdj34llKWyPIlfvLeFqyIdau178sqjCjd/dg+BwGENCATh4sBo7UtjIgAePt1i flha/MzqVGioxlvGRQbBVnZiLtpkT9rdbqP1b4twmtYtJfFkh+ZQXBRt3rrWQDf6LiRv sX5w02bqE2WAjHcFGu9eFo6IBV9LKkeB/nIKxJ6w8r5fovjohhQ+jN1esM0qRKoVJLzD 7kqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+nqjIwk41+U9tH9eGUNa4mmueteq5RxG7HgTGB7HKEw=; b=k4fnyAO2RCo3Vg8gsx0kn3OxtV9hh/SQ5lfjvfUkWiypioViGcJNY6hwwAeqGr5yhg mmRLRG88d33n+KvwBGBkoLTG5eOJ3zOsY94mWu8OHx69uuM6WbQf2rJE9z6bA+H5Sv6e hxNMdlHCsgHEB3x9MkNIP2ZfgcWR6hCen9cuudAhXAI9++VfKGpZDOu85Zex7IMqqJsT aw88PnZhkg5Yq8Ln/jnY3Uiqz1uoMxuXX3Q+v00YZ1IRSEq2S7HmojdBaBpT6MRp/BwM 9mB6LEYuQmeAhpHq2CI+XB3z3k6m8LdDczA23ayCZlA103S0+YlCnRN0iyUjO6cRNxH3 eR9w== X-Gm-Message-State: AOAM532kSeLlUQ5Jh7Bzy0anj4omlSjKEGOv4DfMd9OGnbHBE0YBFjEu iDlZ7UBto+3j+Dg5xoO9AY0= X-Google-Smtp-Source: ABdhPJyhWQxVQrsZzaIFTMTAEpHxBdK84+D+Vb58aq+d8wtkU/Slp1916zxM0upFzx4h23XtLNMLzQ== X-Received: by 2002:a05:6a00:888:b0:4a8:56c:d2c with SMTP id q8-20020a056a00088800b004a8056c0d2cmr6578052pfj.40.1638368684323; Wed, 01 Dec 2021 06:24:44 -0800 (PST) Received: from sbwpb-arch.flets-east.jp ([2400:4052:6980:3800:dba7:2b1f:3f26:a5ec]) by smtp.gmail.com with ESMTPSA id o7sm18293825pgq.59.2021.12.01.06.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 06:24:43 -0800 (PST) From: Tsuchiya Yuto To: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Tsuchiya Yuto , Dan Carpenter Subject: [PATCH v1 1/1] media: atomisp: fix "variable dereferenced before check 'asd'" Date: Wed, 1 Dec 2021 23:19:04 +0900 Message-Id: <20211201141904.47231-1-kitakar@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are two occurrences where the variable 'asd' is dereferenced before check. Fix this issue by using the variable after the check. Link: https://lore.kernel.org/linux-media/20211122074122.GA6581@kili/ Reported-by: Dan Carpenter Signed-off-by: Tsuchiya Yuto --- I didn't add the Fixes tag considering that the media_stage tree can be rebased. Here is the commit of the media_stage tree pointed out in the Link, c10bcb13462e ("media: atomisp: add NULL check for asd obtained from atomisp_video_pipe") Can be applied on the top of media_stage tree. --- drivers/staging/media/atomisp/pci/atomisp_cmd.c | 3 ++- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 5a90cc31cd1a..97d5a528969b 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -5185,7 +5185,7 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev, int (*configure_pp_input)(struct atomisp_sub_device *asd, unsigned int width, unsigned int height) = configure_pp_input_nop; - u16 stream_index = atomisp_source_pad_to_stream_id(asd, source_pad); + u16 stream_index; const struct atomisp_in_fmt_conv *fc; int ret, i; @@ -5194,6 +5194,7 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev, __func__, vdev->name); return -EINVAL; } + stream_index = atomisp_source_pad_to_stream_id(asd, source_pad); v4l2_fh_init(&fh.vfh, vdev); diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 562789c75299..8fd470efd658 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1182,7 +1182,7 @@ int __atomisp_reqbufs(struct file *file, void *fh, struct ia_css_frame *frame; struct videobuf_vmalloc_memory *vm_mem; u16 source_pad = atomisp_subdev_source_pad(vdev); - u16 stream_id = atomisp_source_pad_to_stream_id(asd, source_pad); + u16 stream_id; int ret = 0, i = 0; if (!asd) { @@ -1190,6 +1190,7 @@ int __atomisp_reqbufs(struct file *file, void *fh, __func__, vdev->name); return -EINVAL; } + stream_id = atomisp_source_pad_to_stream_id(asd, source_pad); if (req->count == 0) { mutex_lock(&pipe->capq.vb_lock); -- 2.34.1