All of lore.kernel.org
 help / color / mirror / Atom feed
From: pierre Kuo <vichy.kuo@gmail.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org
Cc: linux-kernel@vger.kernel.org, pierre Kuo <vichy.kuo@gmail.com>
Subject: [PATCH 2/2] driver core: platform: provide devm_platform_iounremap_resource
Date: Sun, 20 Sep 2020 19:38:08 +0800	[thread overview]
Message-ID: <20200920113808.22223-2-vichy.kuo@gmail.com> (raw)
In-Reply-To: <20200920113808.22223-1-vichy.kuo@gmail.com>

Combine platform_get_resource() and devm_iounremap_resource() to release
the iomem allocated by devm_platform_get_and_ioremap_resource().

Signed-off-by: pierre Kuo <vichy.kuo@gmail.com>
---
 drivers/base/platform.c         | 24 ++++++++++++++++++++++++
 include/linux/platform_device.h |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index e5d8a0503b4f..e2655c00873f 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -84,6 +84,30 @@ devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
 }
 EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource);
 
+/**
+ * devm_platform_iounremap_resource - call devm_iounremap_resource() for a
+ *				      platform device with memory that addr points to.
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ *        resource management
+ * @index: resource index
+ * @addr: address to be unmap.
+ */
+void
+devm_platform_iounremap_resource(struct platform_device *pdev,
+				 unsigned int index, void __iomem *addr)
+{
+	struct resource *r;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, index);
+	if (!r)
+		dev_err(&pdev->dev,
+			"MEM resource index %d not found\n", index);
+	else
+		devm_iounremap_resource(&pdev->dev, r, addr);
+}
+EXPORT_SYMBOL_GPL(devm_platform_iounremap_resource);
+
 /**
  * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
  *				    device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 77a2aada106d..75da15937679 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -67,6 +67,10 @@ devm_platform_ioremap_resource_wc(struct platform_device *pdev,
 extern void __iomem *
 devm_platform_ioremap_resource_byname(struct platform_device *pdev,
 				      const char *name);
+extern void
+devm_platform_iounremap_resource(struct platform_device *pdev,
+				 unsigned int index,
+				 void __iomem *addr);
 extern int platform_get_irq(struct platform_device *, unsigned int);
 extern int platform_get_irq_optional(struct platform_device *, unsigned int);
 extern int platform_irq_count(struct platform_device *);
-- 
2.17.1


  reply	other threads:[~2020-09-20 11:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20 11:38 [PATCH 1/2] lib: devres: provide devm_iounremap_resource() pierre Kuo
2020-09-20 11:38 ` pierre Kuo [this message]
2020-09-29  6:21   ` [PATCH 2/2] driver core: platform: provide devm_platform_iounremap_resource pierre kuo
2020-10-02 13:45     ` Greg KH
2020-10-04 16:21       ` pierre kuo
2020-10-04 16:47         ` Greg KH
2020-10-05 15:23           ` pierre kuo
2020-10-05 15:31             ` Greg KH

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=20200920113808.22223-2-vichy.kuo@gmail.com \
    --to=vichy.kuo@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.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.