Re: [PATCH 2/2] driver core: platform: provide devm_platform_iounremap_resource

From: pierre kuo
Date: Tue Sep 29 2020 - 02:21:57 EST


Hi Greg and Rafael:
Would you please help to review these 2 patches?

https://lkml.org/lkml/2020/9/20/112
https://lkml.org/lkml/2020/9/20/113

Appreciate ur help in advance.

>
> 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@xxxxxxxxx>
> ---
> 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
>