From patchwork Wed Nov 16 19:16:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 9432427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 27A4260476 for ; Wed, 16 Nov 2016 19:19:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14C9229119 for ; Wed, 16 Nov 2016 19:19:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 094262911A; Wed, 16 Nov 2016 19:19:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9FA962911F for ; Wed, 16 Nov 2016 19:19:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c75i9-0004v8-Q5; Wed, 16 Nov 2016 19:17:33 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c75i4-0004rr-7O; Wed, 16 Nov 2016 19:17:28 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1c75hZ-0001qU-Ki; Wed, 16 Nov 2016 19:16:57 +0000 From: Colin King To: Mauro Carvalho Chehab , Matthias Brugger , Hans Verkuil , Wei Yongjun , Andrew-CT Chen , linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH] [media] VPU: mediatek: fix dereference of pdev before checking it is null Date: Wed, 16 Nov 2016 19:16:50 +0000 Message-Id: <20161116191650.11486-1-colin.king@canonical.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161116_111728_446196_9D457838 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King pdev is dereferenced using platform_get_drvdata before a check to see if it is null, hence there could be a potential null pointer dereference issue. Instead, first check if pdev is null and only then deference pdev when initializing vpu. Found with static analysis by CoverityScan, CID 1357797 Signed-off-by: Colin Ian King Reviewed-by: Matthias Brugger Reviewed-by: Andrew-CT Chen --- drivers/media/platform/mtk-vpu/mtk_vpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c b/drivers/media/platform/mtk-vpu/mtk_vpu.c index c9bf58c..41f31b2 100644 --- a/drivers/media/platform/mtk-vpu/mtk_vpu.c +++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c @@ -523,9 +523,9 @@ static int load_requested_vpu(struct mtk_vpu *vpu, int vpu_load_firmware(struct platform_device *pdev) { - struct mtk_vpu *vpu = platform_get_drvdata(pdev); + struct mtk_vpu *vpu; struct device *dev = &pdev->dev; - struct vpu_run *run = &vpu->run; + struct vpu_run *run; const struct firmware *vpu_fw = NULL; int ret; @@ -533,6 +533,8 @@ int vpu_load_firmware(struct platform_device *pdev) dev_err(dev, "VPU platform device is invalid\n"); return -EINVAL; } + vpu = platform_get_drvdata(pdev); + run = &vpu->run; mutex_lock(&vpu->vpu_mutex); if (vpu->fw_loaded) {