Discussion:
[PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
(too old to reply)
Greg KH
2020-03-17 19:20:51 UTC
Permalink
Since commit "drivers: provide devm_platform_ioremap_resource()",
it was wrap platform_get_resource() and devm_ioremap_resource() as
single helper devm_platform_ioremap_resource(). but now, many drivers
still used platform_get_resource() and devm_ioremap_resource()
together in the kernel tree. The reason can not be replaced is they
still need use the resource variables obtained by platform_get_resource().
so provide this helper.
---
- rename the function to
devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
- make the last parameter res as optional by Geert's suggestion.
- No change.
drivers/base/platform.c | 22 ++++++++++++++++++++++
include/linux/platform_device.h | 3 +++
2 files changed, 25 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 7fa654f1288b..9f6a78f79235 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
EXPORT_SYMBOL_GPL(platform_get_resource);
#ifdef CONFIG_HAS_IOMEM
+/**
+ * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
+ * platform device and get resource
+ *
+ * resource management
+ */
+void __iomem *
+devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
+ unsigned int index, struct resource **res)
+{
+ struct resource *r;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, index);
+ if (res)
+ *res = r;
What happens if that call fails? Shouldn't that be checked?

thanks,

greg k-h
Geert Uytterhoeven
2020-03-17 19:35:16 UTC
Permalink
Hi Greg,
Post by Greg KH
Since commit "drivers: provide devm_platform_ioremap_resource()",
it was wrap platform_get_resource() and devm_ioremap_resource() as
single helper devm_platform_ioremap_resource(). but now, many drivers
still used platform_get_resource() and devm_ioremap_resource()
together in the kernel tree. The reason can not be replaced is they
still need use the resource variables obtained by platform_get_resource().
so provide this helper.
---
- rename the function to
devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
- make the last parameter res as optional by Geert's suggestion.
- No change.
drivers/base/platform.c | 22 ++++++++++++++++++++++
include/linux/platform_device.h | 3 +++
2 files changed, 25 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 7fa654f1288b..9f6a78f79235 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
EXPORT_SYMBOL_GPL(platform_get_resource);
#ifdef CONFIG_HAS_IOMEM
+/**
+ * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
+ * platform device and get resource
+ *
+ * resource management
+ */
+void __iomem *
+devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
+ unsigned int index, struct resource **res)
+{
+ struct resource *r;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, index);
+ if (res)
+ *res = r;
What happens if that call fails? Shouldn't that be checked?
Then devm_ioremap_resource() will print an error message, and return
an error.
It's designed to be pipelined that way, so you have to check for an error
only once.

Gr{oetje,eeting}s,

Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ***@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Loading...