From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751261AbcIIBZV (ORCPT ); Thu, 8 Sep 2016 21:25:21 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:38253 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750787AbcIIBZU (ORCPT ); Thu, 8 Sep 2016 21:25:20 -0400 Message-ID: <1473384314.10811.0.camel@mtksdaap41> Subject: Re: [PATCH] [media] VPU: mediatek: fix null pointer dereference on pdev From: andrew-ct chen To: Colin King CC: Mauro Carvalho Chehab , Matthias Brugger , Hans Verkuil , "Wei Yongjun" , Tiffany Lin , , , , Date: Fri, 9 Sep 2016 09:25:14 +0800 In-Reply-To: <20160907171027.16424-1-colin.king@canonical.com> References: <20160907171027.16424-1-colin.king@canonical.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-09-07 at 18:10 +0100, Colin King wrote: > From: Colin Ian King > > pdev is being null checked, however, prior to that it is being > dereferenced by platform_get_drvdata. Move the assignments of > vpu and run to after the pdev null check to avoid a potential > null pointer dereference. > Reviewed-by:Andrew-CT Chen > Signed-off-by: Colin Ian King > --- > drivers/media/platform/mtk-vpu/mtk_vpu.c | 7 +++++-- > 1 file changed, 5 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..43907a3 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; > > @@ -534,6 +534,9 @@ int vpu_load_firmware(struct platform_device *pdev) > return -EINVAL; > } > > + vpu = platform_get_drvdata(pdev); > + run = &vpu->run; > + > mutex_lock(&vpu->vpu_mutex); > if (vpu->fw_loaded) { > mutex_unlock(&vpu->vpu_mutex);