From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932213AbcF1Kon (ORCPT ); Tue, 28 Jun 2016 06:44:43 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:15099 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752467AbcF1Kol (ORCPT ); Tue, 28 Jun 2016 06:44:41 -0400 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Tue, 28 Jun 2016 03:37:35 -0700 From: Jon Hunter To: Stephen Warren , Thierry Reding , Alexandre Courbot CC: , , Jon Hunter Subject: [PATCH 3/6] soc/tegra: pmc: Don't populate soc data until register space is mapped Date: Tue, 28 Jun 2016 11:38:25 +0100 Message-ID: <1467110308-22126-4-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1467110308-22126-1-git-send-email-jonathanh@nvidia.com> References: <1467110308-22126-1-git-send-email-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The public functions exported by the PMC driver use the presence of the soc data pointer to determine if the PMC device is configured and the registers can be accessed. However, the soc data is populated before the PMC register space is mapped and this opens a window where the soc data pointer is valid but the register space has not yet been mapped which could lead to a crash. Furthermore, if the mapping of the PMC register space fails, then the soc data pointer is not cleared and so would expose a larger window where a crash could occur. Fix this by initialising the soc data pointer after the PMC register space has been mapped. Signed-off-by: Jon Hunter --- drivers/soc/tegra/pmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index 2e031c4ad547..ed2b2c83e4eb 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -1540,8 +1540,6 @@ static int __init tegra_pmc_early_init(void) pr_err("failed to get PMC registers\n"); return -ENXIO; } - - pmc->soc = match->data; } pmc->base = ioremap_nocache(regs.start, resource_size(®s)); @@ -1553,6 +1551,8 @@ static int __init tegra_pmc_early_init(void) mutex_init(&pmc->powergates_lock); if (np) { + pmc->soc = match->data; + /* Create a bit-map of the available and valid partitions */ for (i = 0; i < pmc->soc->num_powergates; i++) if (pmc->soc->powergates[i]) -- 2.1.4