Skip to contentSkip to conversation

pmdomain: mediatek: Use devm_platform_get_and_ioremap_resource() in init_scp()

PATCH Superseded Markus Elfring 4 participants 10 messages Feb 5, 2024 – Feb 6, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pmdomain: mediatek: Use devm_platform_get_and_ioremap_resource() in init_scp()

From: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2024 15:08:27 +0100

A wrapper function is available since the commit 890cc39a879906b63912482dfc41944579df2dc6 ("drivers: provide devm_platform_get_and_ioremap_resource()").
Thus reuse existing functionality instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/pmdomain/mediatek/mtk-scpsys.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pmdomain/mediatek/mtk-scpsys.c +1 -2
index b374d01fdac7..9e7f0771e7e4 100644
@@ -441,8 +441,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
 	scp->dev = &pdev->dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	scp->base = devm_ioremap_resource(&pdev->dev, res);
+	scp->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(scp->base))
 		return ERR_CAST(scp->base);
 

--
2.43.0

#1 lore raw

Hi Markus,

Quoted 10 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2024 15:08:27 +0100

A wrapper function is available since the commit 890cc39a879906b63912482dfc41944579df2dc6 ("drivers: provide devm_platform_get_and_ioremap_resource()").
Thus reuse existing functionality instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Thanks for your patch!

drivers/pmdomain/mediatek/mtk-scpsys.c static struct scp *init_scp(struct platform_device *pdev, · line 444

Quoted 9 lines
drivers/pmdomain/mediatek/mtk-scpsys.c +1 -2
@@ -441,8 +441,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
        scp->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       scp->base = devm_ioremap_resource(&pdev->dev, res);
+       scp->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

Given res is further unused, please use devm_platform_ioremap_resource() instead, and remove the local variable res.

drivers/pmdomain/mediatek/mtk-scpsys.c static struct scp *init_scp(struct platform_device *pdev, · line 447

Quoted 3 lines
drivers/pmdomain/mediatek/mtk-scpsys.c +0 -0
        if (IS_ERR(scp->base))
                return ERR_CAST(scp->base);
 

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#2 lore raw
Quoted 11 lines

drivers/pmdomain/mediatek/mtk-scpsys.c static struct scp *init_scp(struct platform_device *pdev, · line 444

Quoted 8 lines

+++ b/drivers/pmdomain/mediatek/mtk-scpsys.c

drivers/pmdomain/mediatek/mtk-scpsys.c +1 -2
@@ -441,8 +441,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
        scp->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       scp->base = devm_ioremap_resource(&pdev->dev, res);
+       scp->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

Given res is further unused, please use devm_platform_ioremap_resource() instead, and remove the local variable res.

I got another idea after looking at the implementation of the function “devm_platform_get_and_ioremap_resource” once more.
https://elixir.bootlin.com/linux/v6.8-rc3/source/drivers/base/platform.c#L87

It seems that it is supported to pass a null pointer for the last parameter (while this possibility is not mentioned in the interface description so far). How do you think about to benefit from such a design option any more (instead of the determination of a corresponding platform device)?

Regards,
Markus

#3 lore raw

Hi Markus,

Quoted 12 lines · Markus Elfring
Quoted 11 lines

drivers/pmdomain/mediatek/mtk-scpsys.c static struct scp *init_scp(struct platform_device *pdev, · line 444

Quoted 8 lines

+++ b/drivers/pmdomain/mediatek/mtk-scpsys.c

drivers/pmdomain/mediatek/mtk-scpsys.c +1 -2
@@ -441,8 +441,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
        scp->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       scp->base = devm_ioremap_resource(&pdev->dev, res);
+       scp->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

Given res is further unused, please use devm_platform_ioremap_resource() instead, and remove the local variable res.

Quoted 8 lines

I got another idea after looking at the implementation of the function “devm_platform_get_and_ioremap_resource” once more.
https://elixir.bootlin.com/linux/v6.8-rc3/source/drivers/base/platform.c#L87

It seems that it is supported to pass a null pointer for the last parameter (while this possibility is not mentioned in the interface description so far). How do you think about to benefit from such a design option any more (instead of the determination of a corresponding platform device)?

Yes, you can pass a NULL pointer as the last parameter.
And as this is very common, the wrapper devm_platform_ioremap_resource() exists.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#4 lore raw

…

Quoted 3 lines
Quoted 3 lines

I got another idea after looking at the implementation of the function “devm_platform_get_and_ioremap_resource” once more.
https://elixir.bootlin.com/linux/v6.8-rc3/source/drivers/base/platform.c#L87

…

Quoted 1 line

Yes, you can pass a NULL pointer as the last parameter.

Would you like to support any approaches which can make interface descriptions clearer for such an implementation detail?

Quoted 1 line

And as this is very common, the wrapper devm_platform_ioremap_resource() exists.

I find further collateral evolution interesting for the involved parameter reduction.

Regards,
Markus

#5 lore raw

PATCH v2 1/1 pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

In reply to Geert Uytterhoeven

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2024 10:05:34 +0100
Subject: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

A wrapper function is available since the commit 7945f929f1a77a1c8887a97ca07f87626858ff42 ("drivers: provide devm_platform_ioremap_resource()").

* Thus reuse existing functionality instead of keeping duplicate source code.

* Delete a local variable which became unnecessary with this refactoring.

This issue was transformed by using the Coccinelle software.

---

v2:
The transformation pattern was adjusted based on advices by known contributors.

Examples:
* Doug Anderson
* Geert Uytterhoeven
* Robin Murphy

 drivers/pmdomain/mediatek/mtk-scpsys.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pmdomain/mediatek/mtk-scpsys.c +1 -3
index b374d01fdac7..59a7a8c261ed 100644
@@ -425,7 +425,6 @@ static struct scp *init_scp(struct platform_device *pdev,
 			bool bus_prot_reg_update)
 {
 	struct genpd_onecell_data *pd_data;
-	struct resource *res;
 	int i, j;
 	struct scp *scp;
 	struct clk *clk[CLK_MAX];
@@ -441,8 +440,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
 	scp->dev = &pdev->dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	scp->base = devm_ioremap_resource(&pdev->dev, res);
+	scp->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(scp->base))
 		return ERR_CAST(scp->base);
 

--
2.43.0

Reviewed-by on v2 1/1
#6 lore raw

Re: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

Quoted 17 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2024 10:05:34 +0100
Subject: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

A wrapper function is available since the commit 7945f929f1a77a1c8887a97ca07f87626858ff42 ("drivers: provide devm_platform_ioremap_resource()").

* Thus reuse existing functionality instead of keeping duplicate source code.

* Delete a local variable which became unnecessary with this refactoring.

This issue was transformed by using the Coccinelle software.

---

Quoted 7 lines

v2:
The transformation pattern was adjusted based on advices by known contributors.

Examples:
* Doug Anderson
* Geert Uytterhoeven
* Robin Murphy

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
maintainer Reviewed-by on v2 1/1
#7 lore raw

Re: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

In reply to Markus Elfring

Il 06/02/24 10:21, Markus Elfring ha scritto:

Quoted 7 lines

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2024 10:05:34 +0100
Subject: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

A wrapper function is available since the commit 7945f929f1a77a1c8887a97ca07f87626858ff42 ("drivers: provide devm_platform_ioremap_resource()").

Quoted 8 lines

* Thus reuse existing functionality instead of keeping duplicate source code.

* Delete a local variable which became unnecessary with this refactoring.

This issue was transformed by using the Coccinelle software.

#8 lore raw

Re: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

In reply to Markus Elfring
Quoted 8 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2024 10:05:34 +0100
Subject: [PATCH v2] pmdomain: mediatek: Use devm_platform_ioremap_resource() in init_scp()

A wrapper function is available since the commit 7945f929f1a77a1c8887a97ca07f87626858ff42 ("drivers: provide devm_platform_ioremap_resource()").

Quoted 8 lines

* Thus reuse existing functionality instead of keeping duplicate source code.

* Delete a local variable which became unnecessary with this refactoring.

This issue was transformed by using the Coccinelle software.

Applied for next, thanks!

Kind regards
Uffe

Quoted 39 lines

---

v2:
The transformation pattern was adjusted based on advices by known contributors.

Examples:
* Doug Anderson
* Geert Uytterhoeven
* Robin Murphy

 drivers/pmdomain/mediatek/mtk-scpsys.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pmdomain/mediatek/mtk-scpsys.c +1 -4
index b374d01fdac7..59a7a8c261ed 100644
@@ -425,7 +425,6 @@ static struct scp *init_scp(struct platform_device *pdev,
                        bool bus_prot_reg_update)
 {
        struct genpd_onecell_data *pd_data;
-       struct resource *res;
        int i, j;
        struct scp *scp;
        struct clk *clk[CLK_MAX];
@@ -441,8 +440,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
        scp->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       scp->base = devm_ioremap_resource(&pdev->dev, res);
+       scp->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(scp->base))
                return ERR_CAST(scp->base);
 
--

2.43.0

#9 lore raw
In reply to Geert Uytterhoeven

Il 05/02/24 17:31, Geert Uytterhoeven ha scritto:

Quoted 20 lines

Hi Markus,

Quoted 10 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2024 15:08:27 +0100

A wrapper function is available since the commit 890cc39a879906b63912482dfc41944579df2dc6 ("drivers: provide devm_platform_get_and_ioremap_resource()").
Thus reuse existing functionality instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Thanks for your patch!

Quoted 4 lines
drivers/pmdomain/mediatek/mtk-scpsys.c +0 -0
@@ -441,8 +441,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 
Quoted 9 lines

drivers/pmdomain/mediatek/mtk-scpsys.c static struct scp *init_scp(struct platform_device *pdev, · line 444

Quoted 5 lines
drivers/pmdomain/mediatek/mtk-scpsys.c +1 -2
         scp->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       scp->base = devm_ioremap_resource(&pdev->dev, res);
+       scp->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

Given res is further unused, please use devm_platform_ioremap_resource() instead, and remove the local variable res.

Agreed: res will never be used.

Cheers,
Angelo