2023-07-05 11:58:27

by 李扬韬

[permalink] [raw]
Subject: [PATCH] hwrng: timeriomem - Use devm_platform_get_and_ioremap_resource()

Convert platform_get_resource(), devm_ioremap_resource() to a single
call to devm_platform_get_and_ioremap_resource(), as this is exactly
what this function does.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/char/hw_random/timeriomem-rng.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c
index 26f322d19a88..3db9d868efb1 100644
--- a/drivers/char/hw_random/timeriomem-rng.c
+++ b/drivers/char/hw_random/timeriomem-rng.c
@@ -113,16 +113,6 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
return -EINVAL;
}

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res)
- return -ENXIO;
-
- if (res->start % 4 != 0 || resource_size(res) < 4) {
- dev_err(&pdev->dev,
- "address must be at least four bytes wide and 32-bit aligned\n");
- return -EINVAL;
- }
-
/* Allocate memory for the device structure (and zero it) */
priv = devm_kzalloc(&pdev->dev,
sizeof(struct timeriomem_rng_private), GFP_KERNEL);
@@ -131,6 +121,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, priv);

+ priv->io_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ if (IS_ERR(priv->io_base))
+ return PTR_ERR(priv->io_base);
+
+ if (res->start % 4 != 0 || resource_size(res) < 4) {
+ dev_err(&pdev->dev,
+ "address must be at least four bytes wide and 32-bit aligned\n");
+ return -EINVAL;
+ }
+
if (pdev->dev.of_node) {
int i;

@@ -158,11 +158,6 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
priv->rng_ops.name = dev_name(&pdev->dev);
priv->rng_ops.read = timeriomem_rng_read;

- priv->io_base = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR(priv->io_base)) {
- return PTR_ERR(priv->io_base);
- }
-
/* Assume random data is already available. */
priv->present = 1;
complete(&priv->completion);
--
2.39.0



2023-07-07 17:13:03

by Martin Kaiser

[permalink] [raw]
Subject: Re: [PATCH] hwrng: timeriomem - Use devm_platform_get_and_ioremap_resource()

Hi,

Thus wrote Yangtao Li ([email protected]):

> Convert platform_get_resource(), devm_ioremap_resource() to a single
> call to devm_platform_get_and_ioremap_resource(), as this is exactly
> what this function does.

> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/char/hw_random/timeriomem-rng.c | 25 ++++++++++---------------
> 1 file changed, 10 insertions(+), 15 deletions(-)

> diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c
> index 26f322d19a88..3db9d868efb1 100644
> --- a/drivers/char/hw_random/timeriomem-rng.c
> +++ b/drivers/char/hw_random/timeriomem-rng.c
> @@ -113,16 +113,6 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
> return -EINVAL;
> }

> - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - if (!res)
> - return -ENXIO;
> -
> - if (res->start % 4 != 0 || resource_size(res) < 4) {
> - dev_err(&pdev->dev,
> - "address must be at least four bytes wide and 32-bit aligned\n");
> - return -EINVAL;
> - }
> -
> /* Allocate memory for the device structure (and zero it) */
> priv = devm_kzalloc(&pdev->dev,
> sizeof(struct timeriomem_rng_private), GFP_KERNEL);
> @@ -131,6 +121,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev)

> platform_set_drvdata(pdev, priv);

> + priv->io_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> + if (IS_ERR(priv->io_base))
> + return PTR_ERR(priv->io_base);
> +
> + if (res->start % 4 != 0 || resource_size(res) < 4) {
> + dev_err(&pdev->dev,
> + "address must be at least four bytes wide and 32-bit aligned\n");
> + return -EINVAL;
> + }
> +
> if (pdev->dev.of_node) {
> int i;

> @@ -158,11 +158,6 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
> priv->rng_ops.name = dev_name(&pdev->dev);
> priv->rng_ops.read = timeriomem_rng_read;

> - priv->io_base = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR(priv->io_base)) {
> - return PTR_ERR(priv->io_base);
> - }
> -
> /* Assume random data is already available. */
> priv->present = 1;
> complete(&priv->completion);
> --
> 2.39.0

Looks ok to me.

Reviewed-by: Martin Kaiser <[email protected]>

I was wondering if we really have to check res->start and resource_size(res)
that we read from the device tree. Other drivers don't check these settings
and use devm_platform_ioremap_resource(pdev, 0).

Best regards,
Martin

2023-07-14 09:09:13

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] hwrng: timeriomem - Use devm_platform_get_and_ioremap_resource()

On Wed, Jul 05, 2023 at 07:52:42PM +0800, Yangtao Li wrote:
> Convert platform_get_resource(), devm_ioremap_resource() to a single
> call to devm_platform_get_and_ioremap_resource(), as this is exactly
> what this function does.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/char/hw_random/timeriomem-rng.c | 25 ++++++++++---------------
> 1 file changed, 10 insertions(+), 15 deletions(-)

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt