Linux-PM Archive on lore.kernel.org
 help / color / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: linux-kernel@vger.kernel.org
Cc: Wolfram Sang <wsa@the-dreams.de>,
	Eduardo Valentin <eduardo.valentin@ti.com>,
	Zhang Rui <rui.zhang@intel.com>,
	linux-pm@vger.kernel.org
Subject: [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation
Date: Tue, 23 Jul 2013 20:02:00 +0200
Message-ID: <1374602524-3398-28-git-send-email-wsa@the-dreams.de> (raw)
In-Reply-To: <1374602524-3398-1-git-send-email-wsa@the-dreams.de>

When cleaning up usage of devm_ioremap_resource, I found that resource
allocation in this driver is ugly and buggy. If resource[0] is not
found, bgp->base will end up NULL, so OOPS. All other resources get
ioremapped, but their pointers are discarded, so why bother. So, let's
keep things simple. Just remap resource[0] and pass the error, if any.
Compile tested only, due to no hardware.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
---
Please apply via the subsystem-tree.

 drivers/thermal/ti-soc-thermal/ti-bandgap.c |   20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
index 9dfd471..416be5d 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
@@ -1130,7 +1130,6 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
 	const struct of_device_id *of_id;
 	struct ti_bandgap *bgp;
 	struct resource *res;
-	int i;
 
 	/* just for the sake */
 	if (!node) {
@@ -1156,21 +1155,10 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
 		return ERR_PTR(-ENOMEM);
 	}
 
-	i = 0;
-	do {
-		void __iomem *chunk;
-
-		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		if (!res)
-			break;
-		chunk = devm_ioremap_resource(&pdev->dev, res);
-		if (i == 0)
-			bgp->base = chunk;
-		if (IS_ERR(chunk))
-			return ERR_CAST(chunk);
-
-		i++;
-	} while (res);
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	bgp->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(bgp->base))
+		return bgp->base;
 
 	if (TI_BANDGAP_HAS(bgp, TSHUT)) {
 		bgp->tshut_gpio = of_get_gpio(node, 0);
-- 
1.7.10.4


  parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23 18:01 [PATCH 00/27] devm cleanup, part #1, take #3 Wolfram Sang
2013-07-23 18:01 ` [PATCH 03/27] drivers/cpuidle: don't check resource with devm_ioremap_resource Wolfram Sang
2013-07-23 21:26   ` Rafael J. Wysocki
2013-07-23 18:02 ` Wolfram Sang [this message]
2013-07-26 15:43   ` [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation Eduardo Valentin

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=1374602524-3398-28-git-send-email-wsa@the-dreams.de \
    --to=wsa@the-dreams.de \
    --cc=eduardo.valentin@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /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

Linux-PM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pm/0 linux-pm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pm linux-pm/ https://lore.kernel.org/linux-pm \
		linux-pm@vger.kernel.org
	public-inbox-index linux-pm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git