From patchwork Fri Dec 22 10:11:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archit Taneja X-Patchwork-Id: 10129583 X-Patchwork-Delegate: agross@codeaurora.org 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 6E81460318 for ; Fri, 22 Dec 2017 10:11:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C9A929FDC for ; Fri, 22 Dec 2017 10:11:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FF9029FE4; Fri, 22 Dec 2017 10:11:39 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE8D629FDC for ; Fri, 22 Dec 2017 10:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758352AbdLVKLg (ORCPT ); Fri, 22 Dec 2017 05:11:36 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:44082 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752796AbdLVKLS (ORCPT ); Fri, 22 Dec 2017 05:11:18 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id ACEBA60710; Fri, 22 Dec 2017 10:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1513937477; bh=pyr52V++TQ9SsauQNCxw+Ms1pFTG/+iihfP5EYRDCrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcTIdMyXIQYzseqvqsT23bB+36w3JPfBfTFEhhG5NPhpkm8iRBHpU0MllBoR9fL8m CPJyWlvEImuOsgavLpkxcbJNkSn1BJF2izbqO+ZWbkR904X11tqkoCAf0U0BeXrPMq kq3+06WUx6JQrldzhISY6JJ112f8wp0LxG4QW630= Received: from localhost (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: architt@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A3F5F601D9; Fri, 22 Dec 2017 10:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1513937477; bh=pyr52V++TQ9SsauQNCxw+Ms1pFTG/+iihfP5EYRDCrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcTIdMyXIQYzseqvqsT23bB+36w3JPfBfTFEhhG5NPhpkm8iRBHpU0MllBoR9fL8m CPJyWlvEImuOsgavLpkxcbJNkSn1BJF2izbqO+ZWbkR904X11tqkoCAf0U0BeXrPMq kq3+06WUx6JQrldzhISY6JJ112f8wp0LxG4QW630= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A3F5F601D9 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=architt@codeaurora.org From: Archit Taneja To: robdclark@gmail.com, jcrouse@codeaurora.org Cc: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Archit Taneja Subject: [PATCH v2] drm/msm: Fix NULL deref in adreno_load_gpu Date: Fri, 22 Dec 2017 15:41:13 +0530 Message-Id: <20171222101113.31615-1-architt@codeaurora.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171214054150.20943-1-architt@codeaurora.org> References: <20171214054150.20943-1-architt@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The msm/kms driver should work even if there is no GPU device specified in DT. Currently, we get a NULL dereference crash in adreno_load_gpu since the driver assumes that priv->gpu_pdev is non-NULL. Perform an additional check on priv->gpu_pdev before trying to retrieve the msm_gpu pointer from it. v2: Incorporate Jordan's comments: - Simplify the check to share the same error message. - Use dev_err_once() to avoid an error message every time we open the drm device fd. Fixes: eec874ce5ff1 (drm/msm/adreno: load gpu at probe/bind time) Signed-off-by: Archit Taneja Acked-by: Jordan Crouse --- drivers/gpu/drm/msm/adreno/adreno_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/adreno/adreno_device.c b/drivers/gpu/drm/msm/adreno/adreno_device.c index 05022ea2a007..bfb3d689f47d 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_device.c +++ b/drivers/gpu/drm/msm/adreno/adreno_device.c @@ -125,11 +125,14 @@ struct msm_gpu *adreno_load_gpu(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; struct platform_device *pdev = priv->gpu_pdev; - struct msm_gpu *gpu = platform_get_drvdata(priv->gpu_pdev); + struct msm_gpu *gpu = NULL; int ret; + if (pdev) + gpu = platform_get_drvdata(pdev); + if (!gpu) { - dev_err(dev->dev, "no adreno device\n"); + dev_err_once(dev->dev, "no GPU device was found\n"); return NULL; }