aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/platform.c
diff options
context:
space:
mode:
authorAndy Shevchenko <[email protected]>2020-12-09 20:36:38 +0000
committerGreg Kroah-Hartman <[email protected]>2020-12-10 15:31:46 +0000
commit0aec2da436623abe19b80b21dd9fc5ec9300a152 (patch)
tree1375608cdd70a7428b707d9a8240b4a4c6b52c25 /drivers/base/platform.c
parentdyndbg: fix use before null check (diff)
downloadkernel-0aec2da436623abe19b80b21dd9fc5ec9300a152.tar.gz
kernel-0aec2da436623abe19b80b21dd9fc5ec9300a152.zip
driver core: platform: Introduce platform_get_mem_or_io()
There are at least few existing users of the proposed API which retrieves either MEM or IO resource from platform device. Make it common to utilize in the existing and new users. Cc: Eric Auger <[email protected]> Cc: Alex Williamson <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Peng Hao <[email protected]> Cc: Arnd Bergmann <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Diffstat (limited to 'drivers/base/platform.c')
-rw-r--r--drivers/base/platform.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 8ad06daa2eaa..0358dc3ea3ad 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -63,6 +63,21 @@ struct resource *platform_get_resource(struct platform_device *dev,
}
EXPORT_SYMBOL_GPL(platform_get_resource);
+struct resource *platform_get_mem_or_io(struct platform_device *dev,
+ unsigned int num)
+{
+ u32 i;
+
+ for (i = 0; i < dev->num_resources; i++) {
+ struct resource *r = &dev->resource[i];
+
+ if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0)
+ return r;
+ }
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(platform_get_mem_or_io);
+
#ifdef CONFIG_HAS_IOMEM
/**
* devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a