LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Enrico Weigelt <lkml@metux.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: cocci@systeme.lip6.fr, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Gilles Muller <Gilles.Muller@lip6.fr>,
	Himanshu Jha <himanshujha199640@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	Nicolas Palix <nicolas.palix@imag.fr>
Subject: [PATCH] drivers: Inline code in devm_platform_ioremap_resource() from two functions
Date: Fri, 14 Jun 2019 11:22:40 +0200
Message-ID: <032e347f-e575-c89c-fa62-473d52232735@web.de> (raw)
In-Reply-To: <f573b2d3-11d0-92b5-f8ab-4c4b6493e152@metux.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Jun 2019 11:05:33 +0200

Two function calls were combined in this function implementation.
Inline corresponding code so that extra error checks can be avoided here.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/base/platform.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 4d1729853d1a..baadca72f949 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -80,8 +80,8 @@ struct resource *platform_get_resource(struct platform_device *dev,
 EXPORT_SYMBOL_GPL(platform_get_resource);

 /**
- * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
- *				    device
+ * devm_platform_ioremap_resource
+ * Achieve devm_ioremap_resource() functionality for a platform device
  *
  * @pdev: platform device to use both for memory resource lookup as well as
  *        resource management
@@ -91,10 +91,39 @@ EXPORT_SYMBOL_GPL(platform_get_resource);
 void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
 					     unsigned int index)
 {
-	struct resource *res;
+	u32 i;

-	res = platform_get_resource(pdev, IORESOURCE_MEM, index);
-	return devm_ioremap_resource(&pdev->dev, res);
+	for (i = 0; i < pdev->num_resources; i++) {
+		struct resource *res = &pdev->resource[i];
+
+		if (resource_type(res) == IORESOURCE_MEM && index-- == 0) {
+			struct device *dev = &pdev->dev;
+			resource_size_t size = resource_size(res);
+			void __iomem *dest;
+
+			if (!devm_request_mem_region(dev,
+						     res->start,
+						     size,
+						     dev_name(dev))) {
+				dev_err(dev,
+					"can't request region for resource %pR\n",
+					res);
+				return IOMEM_ERR_PTR(-EBUSY);
+			}
+
+			dest = devm_ioremap(dev, res->start, size);
+			if (!dest) {
+				dev_err(dev,
+					"ioremap failed for resource %pR\n",
+					res);
+				devm_release_mem_region(dev, res->start, size);
+				dest = IOMEM_ERR_PTR(-ENOMEM);
+			}
+
+			return dest;
+		}
+	}
+	return IOMEM_ERR_PTR(-EINVAL);
 }
 EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
 #endif /* CONFIG_HAS_IOMEM */
--
2.22.0


  parent reply index

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-06  6:11 [PATCH] coccinelle: api: add devm_platform_ioremap_resource script Himanshu Jha
2019-04-06  6:31 ` Julia Lawall
2019-04-06  6:34   ` Julia Lawall
2019-07-06 12:16     ` [Cocci] " Masahiro Yamada
2019-07-06 13:39       ` Julia Lawall
2019-07-07  9:55         ` Coccinelle: " Markus Elfring
2019-07-07 12:38           ` Masahiro Yamada
2019-04-06 12:36 ` [PATCH] coccinelle: " Markus Elfring
2019-06-08 15:24 ` Coccinelle: " Markus Elfring
2019-06-08 17:26   ` Julia Lawall
2019-06-09  8:55     ` Markus Elfring
2019-06-11 20:40       ` Enrico Weigelt, metux IT consult
2019-06-12  5:28         ` Julia Lawall
2019-06-12  6:24         ` Markus Elfring
2019-06-14  9:22         ` Markus Elfring [this message]
2019-06-14  9:27           ` [Cocci] [PATCH] drivers: Inline code in devm_platform_ioremap_resource() from two functions Julia Lawall
2019-06-15 11:00             ` Markus Elfring
2019-06-14 10:07           ` [PATCH] " Greg Kroah-Hartman
2019-06-17 20:21           ` Enrico Weigelt, metux IT consult
2019-06-18  5:37             ` Markus Elfring
2019-06-18  9:35               ` Enrico Weigelt, metux IT consult
2019-06-18 10:21                 ` Dan Carpenter
2019-06-18 11:44                 ` Markus Elfring

Reply instructions:

You may reply publically 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=032e347f-e575-c89c-fa62-473d52232735@web.de \
    --to=markus.elfring@web.de \
    --cc=Gilles.Muller@lip6.fr \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=gregkh@linuxfoundation.org \
    --cc=himanshujha199640@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml@metux.net \
    --cc=michal.lkml@markovi.net \
    --cc=nicolas.palix@imag.fr \
    --cc=rafael@kernel.org \
    --cc=yamada.masahiro@socionext.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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

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


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


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