[PATCH 1/2] platform_device: add devres function region-reqs
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Fri Jan 5 11:11:50 PST 2024
On Fri, Jan 05, 2024 at 06:22:18PM +0100, Philipp Stanner wrote:
> Some drivers want to use (request) a region exclusively but nevertheless
> create several mappings within that region.
>
> Currently, there is no managed devres function to request a region
> without mapping it.
>
> Add the function devm_platform_get_resource()
>
> Signed-off-by: Philipp Stanner <pstanner at redhat.com>
> ---
> drivers/base/platform.c | 37 +++++++++++++++++++++++++++++++++
> include/linux/platform_device.h | 2 ++
> 2 files changed, 39 insertions(+)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 10c577963418..243b9ec54d04 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -82,6 +82,43 @@ struct resource *platform_get_mem_or_io(struct platform_device *dev,
> }
> EXPORT_SYMBOL_GPL(platform_get_mem_or_io);
>
> +/**
> + * devm_platform_get_and_resource - get and request a resource
This function name is wrong.
> + *
> + * @pdev: the platform device to get the resource from
> + * @type: resource type (either IORESOURCE_MEM or IORESOURCE_IO)
> + * @num: resource index
> + * @name: name to be associated with the request
> + *
> + * Return: a pointer to the resource on success, an ERR_PTR on failure.
> + *
> + * Gets a resource and requests it. Use this instead of
> + * devm_platform_ioremap_resource() only if you have to create several single
> + * mappings with devm_ioremap().
> + */
> +struct resource *devm_platform_get_resource(struct platform_device *pdev,
> + unsigned int type, unsigned int num, const char *name)
> +{
> + struct resource *res;
> +
> + res = platform_get_resource(pdev, type, num);
> + if (!res)
> + return ERR_PTR(-EINVAL);
From devm_platform_get_resource I'd expect that it only does
platform_get_resource() + register a cleanup function to undo it.
> + if (type & IORESOURCE_MEM)
> + res = devm_request_mem_region(&pdev->dev, res->start, res->end, name);
> + else if (type & IORESOURCE_IO)
> + res = devm_request_region(&pdev->dev, res->start, res->end, name);
> + else
> + return ERR_PTR(-EINVAL);
So this part is surprising. IMHO your function's name should include
"request".
> + if (!res)
> + return ERR_PTR(-EBUSY);
> +
> + return res;
> +}
> +EXPORT_SYMBOL_GPL(devm_platform_get_resource);
> +
> #ifdef CONFIG_HAS_IOMEM
> /**
> * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20240105/b76f537d/attachment-0001.sig>
More information about the linux-arm-kernel
mailing list