2020-04-14 16:02:02

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

use devm_platform_get_and_ioremap_resource() to simplify code, which
contains platform_get_resource() and devm_ioremap_resource(), it also
get the resource for use by the following code.

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/i2c/busses/i2c-cadence.c | 3 +--
drivers/i2c/busses/i2c-pca-platform.c | 3 +--
drivers/i2c/busses/i2c-rcar.c | 4 +---
drivers/i2c/busses/i2c-stm32f7.c | 3 +--
4 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 89d58f7d2a25..803c802611eb 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -906,8 +906,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
id->quirks = data->quirks;
}

- r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
+ id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
if (IS_ERR(id->membase))
return PTR_ERR(id->membase);

diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 635dd697ac0b..546426a470cc 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -149,8 +149,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
if (!i2c)
return -ENOMEM;

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- i2c->reg_base = devm_ioremap_resource(&pdev->dev, res);
+ i2c->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(i2c->reg_base))
return PTR_ERR(i2c->reg_base);

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 3b5397aa4ca6..a45c4bf1ec01 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -938,9 +938,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
return PTR_ERR(priv->clk);
}

- priv->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
- priv->io = devm_ioremap_resource(dev, priv->res);
+ priv->io = devm_platform_get_and_ioremap_resource(pdev, 0, &priv->res);
if (IS_ERR(priv->io))
return PTR_ERR(priv->io);

diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 330ffed011e0..cf48f8df4423 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -1940,8 +1940,7 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
if (!i2c_dev)
return -ENOMEM;

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- i2c_dev->base = devm_ioremap_resource(&pdev->dev, res);
+ i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(i2c_dev->base))
return PTR_ERR(i2c_dev->base);
phy_addr = (dma_addr_t)res->start;
--
2.25.0


2020-04-15 22:55:40

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

On Tue, Apr 14, 2020 at 09:48:27PM +0800, Dejin Zheng wrote:
> use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
>
> Signed-off-by: Dejin Zheng <[email protected]>

Applied to for-next, because it seems 'the new way' but...

> - r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
> + id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);

... guys, do you really think this one line reduction improves
readability? Oh well...


Attachments:
(No filename) (671.00 B)
signature.asc (849.00 B)
Download all attachments

2020-04-16 00:20:01

by Dejin Zheng

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

On Wed, Apr 15, 2020 at 12:21:58PM +0200, Wolfram Sang wrote:
> On Tue, Apr 14, 2020 at 09:48:27PM +0800, Dejin Zheng wrote:
> > use devm_platform_get_and_ioremap_resource() to simplify code, which
> > contains platform_get_resource() and devm_ioremap_resource(), it also
> > get the resource for use by the following code.
> >
> > Signed-off-by: Dejin Zheng <[email protected]>
>
> Applied to for-next, because it seems 'the new way' but...
>
> > - r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > - id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
> > + id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
>
> ... guys, do you really think this one line reduction improves
> readability? Oh well...
>
Wolfram, Thank you for accepting it. From my personal point of view,
as long as the direction is correct, even small improvements are
worth doing. Thanks again for your tolerance.

BR,
Dejin


2020-04-17 20:38:33

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

> use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.

I suggest to improve also this change description.

I have tried another script variant out for the semantic patch language.
This source code analysis approach would propose to transform
15 source files (for example in the directory “drivers/i2c”
of the software “Linux next-20200417”).
Would you like to take another look at corresponding change possibilities?

Regards,
Markus

2020-04-17 20:50:35

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

On Thu, Apr 16, 2020 at 3:19 AM Dejin Zheng <[email protected]> wrote:
>
> On Wed, Apr 15, 2020 at 12:21:58PM +0200, Wolfram Sang wrote:
> > On Tue, Apr 14, 2020 at 09:48:27PM +0800, Dejin Zheng wrote:
> > > use devm_platform_get_and_ioremap_resource() to simplify code, which
> > > contains platform_get_resource() and devm_ioremap_resource(), it also
> > > get the resource for use by the following code.
> > >
> > > Signed-off-by: Dejin Zheng <[email protected]>
> >
> > Applied to for-next, because it seems 'the new way' but...
> >
> > > - r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > - id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
> > > + id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
> >
> > ... guys, do you really think this one line reduction improves
> > readability? Oh well...
> >
> Wolfram, Thank you for accepting it. From my personal point of view,
> as long as the direction is correct, even small improvements are
> worth doing. Thanks again for your tolerance.

Do you have plans to move on from janitor work to something serious?

--
With Best Regards,
Andy Shevchenko

2020-04-18 04:17:01

by Dejin Zheng

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: busses: convert to devm_platform_get_and_ioremap_resource

On Fri, Apr 17, 2020 at 11:46:33PM +0300, Andy Shevchenko wrote:
> On Thu, Apr 16, 2020 at 3:19 AM Dejin Zheng <[email protected]> wrote:
> >
> > On Wed, Apr 15, 2020 at 12:21:58PM +0200, Wolfram Sang wrote:
> > > On Tue, Apr 14, 2020 at 09:48:27PM +0800, Dejin Zheng wrote:
> > > > use devm_platform_get_and_ioremap_resource() to simplify code, which
> > > > contains platform_get_resource() and devm_ioremap_resource(), it also
> > > > get the resource for use by the following code.
> > > >
> > > > Signed-off-by: Dejin Zheng <[email protected]>
> > >
> > > Applied to for-next, because it seems 'the new way' but...
> > >
> > > > - r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > > - id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
> > > > + id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
> > >
> > > ... guys, do you really think this one line reduction improves
> > > readability? Oh well...
> > >
> > Wolfram, Thank you for accepting it. From my personal point of view,
> > as long as the direction is correct, even small improvements are
> > worth doing. Thanks again for your tolerance.
>
> Do you have plans to move on from janitor work to something serious?
>
Andy, I want to do��but I don��t know where to start, Could you give me
some suggestions? Thanks very much!

BR,
Dejin
> --
> With Best Regards,
> Andy Shevchenko