devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] New of_io_release_and_unmap()
@ 2015-02-25 19:20 Joshua Clayton
  2015-02-25 19:20 ` [PATCH] of/address: Add of_io_release_and_unmap() Joshua Clayton
  2015-02-25 19:23 ` [RFC] New of_io_release_and_unmap() Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: Joshua Clayton @ 2015-02-25 19:20 UTC (permalink / raw)
  To: Grant Likely, Rob Herring, devicetree, linux-kernel; +Cc: Joshua Clayton

Hello folks,
I notice that io_request_and_map has no inverse.
I would like to add a new function to undo what it does.

Joshua Clayton (1):
  of/address: Add of_io_release_and_unmap()

 drivers/of/address.c       | 29 +++++++++++++++++++++++++++++
 include/linux/of_address.h |  2 ++
 2 files changed, 31 insertions(+)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] of/address: Add of_io_release_and_unmap()
  2015-02-25 19:20 [RFC] New of_io_release_and_unmap() Joshua Clayton
@ 2015-02-25 19:20 ` Joshua Clayton
  2015-02-25 19:23 ` [RFC] New of_io_release_and_unmap() Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Joshua Clayton @ 2015-02-25 19:20 UTC (permalink / raw)
  To: Grant Likely, Rob Herring, devicetree, linux-kernel; +Cc: Joshua Clayton

New Fumction of_io_release_an_unmap frees resources and io memory
allocated by io_request_and_map()

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 drivers/of/address.c       | 29 +++++++++++++++++++++++++++++
 include/linux/of_address.h |  2 ++
 2 files changed, 31 insertions(+)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index ad29069..d0f3b81 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -872,6 +872,7 @@ EXPORT_SYMBOL(of_iomap);
 /*
  * of_io_request_and_map - Requests a resource and maps the memory mapped IO
  *			   for a given device_node
+ *			   Call of_io_release_and_unmap() to free the memory
  * @device:	the device whose io range will be mapped
  * @index:	index of the io range
  * @name:	name of the resource
@@ -882,6 +883,10 @@ EXPORT_SYMBOL(of_iomap);
  *	base = of_io_request_and_map(node, 0, "foo");
  *	if (IS_ERR(base))
  *		return PTR_ERR(base);
+ *
+ * ...
+ *
+ *	return of_io_request_and_map(node, 0, base);
  */
 void __iomem *of_io_request_and_map(struct device_node *np, int index,
 					const char *name)
@@ -906,6 +911,30 @@ void __iomem *of_io_request_and_map(struct device_node *np, int index,
 EXPORT_SYMBOL(of_io_request_and_map);
 
 /**
+ * of_io_release_and_unmap - Unmap memory and release resource
+ *			   associated with a device node
+ * Use this function to free memory requested by of_io_request_and_map()
+ * See the Usage example for of_io_request_and_map
+ *
+ */
+int of_io_release_and_unmap(struct device_node *np, int index,
+				void __iomem *addr)
+{
+	struct resource res;
+	int ret = 0;
+
+	ret = of_address_to_resource(np, index, &res);
+	if (ret)
+		return ret;
+
+	iounmap(addr);
+	release_mem_region(res.start, resource_size(&res));
+
+	return ret;
+}
+EXPORT_SYMBOL(of_io_release_and_unmap);
+
+/**
  * of_dma_get_range - Get DMA range info
  * @np:		device node to get DMA range info
  * @dma_addr:	pointer to store initial DMA address of DMA range
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index d88e81b..f62eb9e 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -107,6 +107,8 @@ extern int of_address_to_resource(struct device_node *dev, int index,
 void __iomem *of_iomap(struct device_node *node, int index);
 void __iomem *of_io_request_and_map(struct device_node *device,
 					int index, const char *name);
+int of_io_release_and_unmap(struct device_node *np, int index,
+					void __iomem *addr);
 #else
 
 #include <linux/io.h>
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC] New of_io_release_and_unmap()
  2015-02-25 19:20 [RFC] New of_io_release_and_unmap() Joshua Clayton
  2015-02-25 19:20 ` [PATCH] of/address: Add of_io_release_and_unmap() Joshua Clayton
@ 2015-02-25 19:23 ` Arnd Bergmann
  2015-02-25 20:00   ` Joshua Clayton
  1 sibling, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2015-02-25 19:23 UTC (permalink / raw)
  To: Joshua Clayton; +Cc: Grant Likely, Rob Herring, devicetree, linux-kernel

On Wednesday 25 February 2015 11:20:41 Joshua Clayton wrote:
> Hello folks,
> I notice that io_request_and_map has no inverse.
> I would like to add a new function to undo what it does.
> 

What do you want to use this for? So far all users are in essential drivers
(clk and clocksource) that result in a boot failure if this goes wrong.

Normal drivers can probably always use devm_ioremap_resource(), which
has an automatic cleanup.

	Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] New of_io_release_and_unmap()
  2015-02-25 19:23 ` [RFC] New of_io_release_and_unmap() Arnd Bergmann
@ 2015-02-25 20:00   ` Joshua Clayton
  0 siblings, 0 replies; 4+ messages in thread
From: Joshua Clayton @ 2015-02-25 20:00 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Grant Likely, Rob Herring, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Wed, Feb 25, 2015 at 11:23 AM, Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> wrote:
> On Wednesday 25 February 2015 11:20:41 Joshua Clayton wrote:
>> Hello folks,
>> I notice that io_request_and_map has no inverse.
>> I would like to add a new function to undo what it does.
>>
>
> What do you want to use this for? So far all users are in essential drivers
> (clk and clocksource) that result in a boot failure if this goes wrong.
>
That explains a lot. It looks (to my n00b eye) like this function leaks some
references, which is more ok if  the ref counters should never be
decremented to 0.

> Normal drivers can probably always use devm_ioremap_resource(), which
> has an automatic cleanup.
>
Hmmm.
My use case is indeed a normal driver, which could definitely
use devm_ioremap_resource()

>         Arnd

That would leave only "completeness" as a reason. Probably not needed.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-25 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-25 19:20 [RFC] New of_io_release_and_unmap() Joshua Clayton
2015-02-25 19:20 ` [PATCH] of/address: Add of_io_release_and_unmap() Joshua Clayton
2015-02-25 19:23 ` [RFC] New of_io_release_and_unmap() Arnd Bergmann
2015-02-25 20:00   ` Joshua Clayton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).