kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib: devres: add a comment about the devm_of_iomap() function
       [not found] <AM6PR04MB496691DDA4447CD5624EE6E680850@AM6PR04MB4966.eurprd04.prod.outlook.com>
@ 2020-06-09 10:46 ` Dan Carpenter
  2020-06-09 14:20   ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-06-09 10:46 UTC (permalink / raw)
  To: Arnd Bergmann, Aisheng Dong
  Cc: Greg Kroah-Hartman, Bartosz Golaszewski, Andrew Morton,
	Tuowen Zhao, Denis Efremov, linux-kernel, kernel-janitors,
	Benjamin Herrenschmidt, BOUGH CHEN, festevam, shawnguo, stefan,
	kernel, linus.walleij, s.hauer, dl-linux-imx, Christophe JAILLET,
	linux-gpio

We recently introduced a bug when we tried to convert of_iomap() to
devm_of_iomap().  The problem was that there were two drivers mapping
the same io region.  The first driver was using of_iomap() and the
second driver was using devm_of_iomap() and the kernel booted fine.
When we converted the first drive to use devm_of_iomap() then the second
driver failed with -EBUSY and the kernel couldn't boot.

Let's add a comment to prevent this sort of mistake in the future.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 lib/devres.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/devres.c b/lib/devres.c
index 6ef51f159c54b..0abe7c1cc4681 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -204,6 +204,12 @@ void __iomem *devm_ioremap_resource_wc(struct device *dev,
  *	base = devm_of_iomap(&pdev->dev, node, 0, NULL);
  *	if (IS_ERR(base))
  *		return PTR_ERR(base);
+ *
+ * Please Note: This is not a one-to-one replacement for of_iomap() because the
+ * of_iomap() function does not track whether the region is already mapped.  If
+ * two drivers try to map the same memory, the of_iomap() function will succeed
+ * but the the devm_of_iomap() function will return -EBUSY.
+ *
  */
 void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
 			    resource_size_t *size)
-- 
2.26.2

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

* Re: [PATCH] lib: devres: add a comment about the devm_of_iomap() function
  2020-06-09 10:46 ` [PATCH] lib: devres: add a comment about the devm_of_iomap() function Dan Carpenter
@ 2020-06-09 14:20   ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2020-06-09 14:20 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Aisheng Dong, Greg Kroah-Hartman, Bartosz Golaszewski,
	Andrew Morton, Tuowen Zhao, Denis Efremov, linux-kernel,
	kernel-janitors, Benjamin Herrenschmidt, BOUGH CHEN, festevam,
	shawnguo, stefan, kernel, linus.walleij, s.hauer, dl-linux-imx,
	Christophe JAILLET, linux-gpio

On Tue, Jun 9, 2020 at 12:47 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> We recently introduced a bug when we tried to convert of_iomap() to
> devm_of_iomap().  The problem was that there were two drivers mapping
> the same io region.  The first driver was using of_iomap() and the
> second driver was using devm_of_iomap() and the kernel booted fine.
> When we converted the first drive to use devm_of_iomap() then the second
> driver failed with -EBUSY and the kernel couldn't boot.
>
> Let's add a comment to prevent this sort of mistake in the future.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Good idea,

Acked-by: Arnd Bergmann <arnd@arndb.de>

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

end of thread, other threads:[~2020-06-09 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <AM6PR04MB496691DDA4447CD5624EE6E680850@AM6PR04MB4966.eurprd04.prod.outlook.com>
2020-06-09 10:46 ` [PATCH] lib: devres: add a comment about the devm_of_iomap() function Dan Carpenter
2020-06-09 14:20   ` Arnd Bergmann

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).