All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	Thierry Reding
	<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Alexandre Courbot
	<gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Jon Hunter <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 2/8] soc: tegra: pmc: Restore base address on probe failure
Date: Thu, 11 Feb 2016 18:03:20 +0000	[thread overview]
Message-ID: <1455213806-21871-3-git-send-email-jonathanh@nvidia.com> (raw)
In-Reply-To: <1455213806-21871-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

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 <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---

Please note that in order to properly fix this, we should lock around the
update on the base address pointer. The 3rd patch of this series adds the
locking and with the locking in place we can then also drop this "tmp"
variable added here.

 drivers/soc/tegra/pmc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c
index 922430322877..900f72f0d757 100644
--- a/drivers/soc/tegra/pmc.c
+++ b/drivers/soc/tegra/pmc.c
@@ -807,7 +807,7 @@ out:
 
 static int tegra_pmc_probe(struct platform_device *pdev)
 {
-	void __iomem *base = pmc->base;
+	void __iomem *base, *tmp;
 	struct resource *res;
 	int err;
 
@@ -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)) {
@@ -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;
 }
 
-- 
2.1.4

  parent reply	other threads:[~2016-02-11 18:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 18:03 [PATCH 0/8] soc: tegra: pmc: Various fixes Jon Hunter
     [not found] ` <1455213806-21871-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-11 18:03   ` [PATCH 1/8] soc: tegra: pmc: Remove non-existing L2 partition for Tegra124 Jon Hunter
2016-02-11 18:03   ` Jon Hunter [this message]
2016-02-11 18:03   ` [PATCH 3/8] soc: tegra: pmc: Protect public functions from potential race conditions Jon Hunter
2016-02-11 18:03   ` [PATCH 4/8] soc: tegra: pmc: Change powergate and rail IDs to be an unsigned type Jon Hunter
2016-02-11 18:03   ` [PATCH 5/8] soc: tegra: pmc: Fix testing of powergate state Jon Hunter
2016-02-11 18:03   ` [PATCH 6/8] soc: tegra: pmc: Fix verification of valid partitions Jon Hunter
2016-02-11 18:03   ` [PATCH 7/8] soc: tegra: pmc: Remove additional check for a valid partition Jon Hunter
2016-02-11 18:03   ` [PATCH 8/8] soc: tegra: pmc: Ensure GPU partition can be toggled on/off by PMC Jon Hunter
     [not found]     ` <1455213806-21871-9-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-12  9:38       ` Jon Hunter
     [not found]         ` <56BDA826.2000304-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-12 17:25           ` Thierry Reding
2016-02-12 18:51             ` Jon Hunter
2016-02-15 12:38       ` [PATCH V2] " Jon Hunter
     [not found]         ` <1455539891-6508-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-26 16:06           ` Mathieu Poirier
     [not found]             ` <CANLsYkwCx13YszW-67F2_KDwxgpzwKQft4eOpJvVM1nkNXGpXQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-26 16:43               ` Jon Hunter
     [not found]                 ` <56D0809E.6060400-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-26 17:47                   ` Mathieu Poirier
2016-02-11 18:15   ` [PATCH 0/8] soc: tegra: pmc: Various fixes Jon Hunter
     [not found]     ` <56BCCFCA.4010009-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-02-11 22:13       ` Mathieu Poirier
2016-02-25 16:56   ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455213806-21871-3-git-send-email-jonathanh@nvidia.com \
    --to=jonathanh-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.