From patchwork Sat Jan 30 14:23:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Weiss X-Patchwork-Id: 12057259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32645C433DB for ; Sat, 30 Jan 2021 16:36:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0984164E0F for ; Sat, 30 Jan 2021 16:36:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229498AbhA3QgF (ORCPT ); Sat, 30 Jan 2021 11:36:05 -0500 Received: from mail.z3ntu.xyz ([128.199.32.197]:60246 "EHLO mail.z3ntu.xyz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbhA3O0i (ORCPT ); Sat, 30 Jan 2021 09:26:38 -0500 Received: from localhost.localdomain (91-115-28-172.adsl.highway.telekom.at [91.115.28.172]) by mail.z3ntu.xyz (Postfix) with ESMTPSA id E4EE1C4D09; Sat, 30 Jan 2021 14:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=z3ntu.xyz; s=z3ntu; t=1612016642; bh=ogHO0gWBqB7dfJUJ5LmZsuLbW5GwhjBNOZ4Ucl5LvUs=; h=From:To:Cc:Subject:Date; b=PVkyvSmszVmxI+29mJcJCWSQvkRTOAW2+YTixg8ohhLUUiTrkX4oYII8L1vhJzOcR xTNJECme5qbB82+Vw13pxFZZEH6T9p09+7sw5k98Ux52tI8t/7T2q9RGNvL5z4RlEB li0zPWANvnPXpwy0kbzETFbTr18wOtD9Qm5JeYNE= From: Luca Weiss To: linux-arm-msm@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, Luca Weiss , Andy Gross , Bjorn Andersson , Rob Clark , Brian Masney , linux-kernel@vger.kernel.org Subject: [PATCH] soc: qcom: ocmem: don't return NULL in of_get_ocmem Date: Sat, 30 Jan 2021 15:23:49 +0100 Message-Id: <20210130142349.53335-1-luca@z3ntu.xyz> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org If ocmem probe fails for whatever reason, of_get_ocmem returned NULL. Without this, users must check for both NULL and IS_ERR on the returned pointer - which didn't happen in drivers/gpu/drm/msm/adreno/adreno_gpu.c leading to a NULL pointer dereference. Fixes: 88c1e9404f1d ("soc: qcom: add OCMEM driver") Signed-off-by: Luca Weiss Reviewed-by: Brian Masney --- drivers/soc/qcom/ocmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/ocmem.c b/drivers/soc/qcom/ocmem.c index 7f9e9944d1ea..f1875dc31ae2 100644 --- a/drivers/soc/qcom/ocmem.c +++ b/drivers/soc/qcom/ocmem.c @@ -189,6 +189,7 @@ struct ocmem *of_get_ocmem(struct device *dev) { struct platform_device *pdev; struct device_node *devnode; + struct ocmem *ocmem; devnode = of_parse_phandle(dev->of_node, "sram", 0); if (!devnode || !devnode->parent) { @@ -202,7 +203,12 @@ struct ocmem *of_get_ocmem(struct device *dev) return ERR_PTR(-EPROBE_DEFER); } - return platform_get_drvdata(pdev); + ocmem = platform_get_drvdata(pdev); + if (!ocmem) { + dev_err(dev, "Cannot get ocmem\n"); + return ERR_PTR(-ENODEV); + } + return ocmem; } EXPORT_SYMBOL(of_get_ocmem);