soc/tegra: pmc: Don't populate SoC data until register space is mapped

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 <jonathanh@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
This commit is contained in:
Jon Hunter 2016-06-28 11:38:25 +01:00 committed by Thierry Reding
parent 11131895cd
commit 718a2426e8

View File

@ -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(&regs));
@ -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])