Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752817AbcKRJuE (ORCPT ); Fri, 18 Nov 2016 04:50:04 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:38518 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbcKRJuC (ORCPT ); Fri, 18 Nov 2016 04:50:02 -0500 Subject: Re: [PATCH] [media] VPU: mediatek: fix dereference of pdev before checking it is null To: Colin King , Mauro Carvalho Chehab , Hans Verkuil , Wei Yongjun , Andrew-CT Chen , linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20161116191650.11486-1-colin.king@canonical.com> Cc: linux-kernel@vger.kernel.org From: Matthias Brugger Message-ID: <981854b7-78fc-567b-1b35-2cbf8d2b5008@suse.com> Date: Fri, 18 Nov 2016 10:49:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161116191650.11486-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1502 Lines: 46 On 16/11/16 20:16, Colin King wrote: > 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 > 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) { >