Skip to content

Commit

Permalink
soc/tegra: pmc: Restore base address on probe failure
Browse files Browse the repository at this point in the history
During early initialisation, the PMC registers are mapped and the PMC SoC
data is populated in the PMC data structure. This allows other drivers
access the PMC register space, via the public Tegra PMC APIs, prior to
probing the PMC device.

When the PMC device is probed, the PMC registers are mapped again and if
successful the initial mapping is freed. If the probing of the PMC device
fails after the registers are remapped, then the registers will be
unmapped and hence the pointer to the PMC registers will be invalid. This
could lead to a potential crash, because once the PMC SoC data pointer is
populated, the driver assumes that the PMC register mapping is also valid
and a user calling any of the public Tegra PMC APIs could trigger an
exception because these APIs don't check that the mapping is still valid.

Fix this by updating the mapping and freeing the original mapping only if
probing the PMC device is successful.

Signed-off-by: Jon Hunter <[email protected]>
Reviewed-by: Mathieu Poirier <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
  • Loading branch information
jonhunter authored and thierryreding committed Apr 5, 2016
1 parent 668419a commit 0259f52
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/soc/tegra/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)

static int tegra_pmc_probe(struct platform_device *pdev)
{
void __iomem *base = pmc->base;
void __iomem *base, *tmp;
struct resource *res;
int err;

Expand All @@ -817,11 +817,9 @@ static int tegra_pmc_probe(struct platform_device *pdev)

/* take over the memory region from the early initialization */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pmc->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pmc->base))
return PTR_ERR(pmc->base);

iounmap(base);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base))
return PTR_ERR(base);

pmc->clk = devm_clk_get(&pdev->dev, "pclk");
if (IS_ERR(pmc->clk)) {
Expand Down Expand Up @@ -850,6 +848,10 @@ static int tegra_pmc_probe(struct platform_device *pdev)
return err;
}

tmp = pmc->base;
pmc->base = base;
iounmap(tmp);

return 0;
}

Expand Down

0 comments on commit 0259f52

Please sign in to comment.