diff mbox series

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

Message ID da6af483-5ee9-45cd-922e-d9d5364674dc@web.de (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series pmdomain: mediatek: Use devm_platform_get_and_ioremap_resource() in init_scp() | expand

Commit Message

Markus Elfring Feb. 5, 2024, 2:23 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/pmdomain/mediatek/mtk-scpsys.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--
2.43.0

Comments

Geert Uytterhoeven Feb. 5, 2024, 4:31 p.m. UTC | #1
Hi Markus,

On Mon, Feb 5, 2024 at 3:23 PM Markus Elfring <Markus.Elfring@web.de> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Thanks for your patch!

> --- a/drivers/pmdomain/mediatek/mtk-scpsys.c
> +++ b/drivers/pmdomain/mediatek/mtk-scpsys.c
> @@ -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.

>         if (IS_ERR(scp->base))
>                 return ERR_CAST(scp->base);
>

Gr{oetje,eeting}s,

                        Geert
Markus Elfring Feb. 5, 2024, 5:28 p.m. UTC | #2
>> +++ b/drivers/pmdomain/mediatek/mtk-scpsys.c
>> @@ -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
Geert Uytterhoeven Feb. 5, 2024, 7:01 p.m. UTC | #3
Hi Markus,

On Mon, Feb 5, 2024 at 6:28 PM Markus Elfring <Markus.Elfring@web.de> wrote:
> >> +++ b/drivers/pmdomain/mediatek/mtk-scpsys.c
> >> @@ -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)?

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
Markus Elfring Feb. 6, 2024, 6:48 a.m. UTC | #4
>> 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> 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?


> 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
AngeloGioacchino Del Regno Feb. 6, 2024, 9:24 a.m. UTC | #5
Il 05/02/24 17:31, Geert Uytterhoeven ha scritto:
> Hi Markus,
> 
> On Mon, Feb 5, 2024 at 3:23 PM Markus Elfring <Markus.Elfring@web.de> wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> 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.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> 
> Thanks for your patch!
> 
>> --- a/drivers/pmdomain/mediatek/mtk-scpsys.c
>> +++ b/drivers/pmdomain/mediatek/mtk-scpsys.c
>> @@ -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.
> 

Agreed: res will never be used.

Cheers,
Angelo
diff mbox series

Patch

diff --git a/drivers/pmdomain/mediatek/mtk-scpsys.c b/drivers/pmdomain/mediatek/mtk-scpsys.c
index b374d01fdac7..9e7f0771e7e4 100644
--- a/drivers/pmdomain/mediatek/mtk-scpsys.c
+++ b/drivers/pmdomain/mediatek/mtk-scpsys.c
@@ -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);