2020-04-19 12:09:41

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH net-next v1] can: ti_hecc: convert to devm_platform_ioremap_resource_byname()

use devm_platform_ioremap_resource_byname() to simplify code,
it contains platform_get_resource_byname() and
devm_ioremap_resource(), and also remove some duplicate error
message.

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/net/can/ti_hecc.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index 94b1491b569f..5f39a4c668b5 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -857,7 +857,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
struct net_device *ndev = (struct net_device *)0;
struct ti_hecc_priv *priv;
struct device_node *np = pdev->dev.of_node;
- struct resource *res, *irq;
+ struct resource *irq;
struct regulator *reg_xceiver;
int err = -ENODEV;

@@ -878,39 +878,22 @@ static int ti_hecc_probe(struct platform_device *pdev)
priv = netdev_priv(ndev);

/* handle hecc memory */
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hecc");
- if (!res) {
- dev_err(&pdev->dev, "can't get IORESOURCE_MEM hecc\n");
- return -EINVAL;
- }
-
- priv->base = devm_ioremap_resource(&pdev->dev, res);
+ priv->base = devm_platform_ioremap_resource_byname(pdev, "hecc");
if (IS_ERR(priv->base)) {
dev_err(&pdev->dev, "hecc ioremap failed\n");
return PTR_ERR(priv->base);
}

/* handle hecc-ram memory */
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hecc-ram");
- if (!res) {
- dev_err(&pdev->dev, "can't get IORESOURCE_MEM hecc-ram\n");
- return -EINVAL;
- }
-
- priv->hecc_ram = devm_ioremap_resource(&pdev->dev, res);
+ priv->hecc_ram = devm_platform_ioremap_resource_byname(pdev,
+ "hecc-ram");
if (IS_ERR(priv->hecc_ram)) {
dev_err(&pdev->dev, "hecc-ram ioremap failed\n");
return PTR_ERR(priv->hecc_ram);
}

/* handle mbx memory */
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mbx");
- if (!res) {
- dev_err(&pdev->dev, "can't get IORESOURCE_MEM mbx\n");
- return -EINVAL;
- }
-
- priv->mbx = devm_ioremap_resource(&pdev->dev, res);
+ priv->mbx = devm_platform_ioremap_resource_byname(pdev, "mbx");
if (IS_ERR(priv->mbx)) {
dev_err(&pdev->dev, "mbx ioremap failed\n");
return PTR_ERR(priv->mbx);
--
2.25.0


2020-04-19 16:35:39

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH net-next v1] can: ti_hecc: convert to devm_platform_ioremap_resource_byname()

> use devm_platform_ioremap_resource_byname() to simplify code,
> it contains platform_get_resource_byname() and
> devm_ioremap_resource(), and also remove some duplicate error
> message.

How do you think about a wording variant like the following?

Use the function “devm_platform_ioremap_resource_byname” to simplify
source code which calls the functions “platform_get_resource_byname”
and “devm_ioremap_resource”.
Remove also a few error messages which became unnecessary with this
software refactoring.


Will any more contributors get into the development mood to achieve
similar collateral evolution by the means of the semantic patch language?
Would you like to increase applications of the Coccinelle software?

Regards,
Markus

2020-04-20 14:42:51

by Dejin Zheng

[permalink] [raw]
Subject: Re: [PATCH net-next v1] can: ti_hecc: convert to devm_platform_ioremap_resource_byname()

On Sun, Apr 19, 2020 at 06:19:12PM +0200, Markus Elfring wrote:
> > use devm_platform_ioremap_resource_byname() to simplify code,
> > it contains platform_get_resource_byname() and
> > devm_ioremap_resource(), and also remove some duplicate error
> > message.
>
> How do you think about a wording variant like the following?
>
> Use the function “devm_platform_ioremap_resource_byname” to simplify
> source code which calls the functions “platform_get_resource_byname”
> and “devm_ioremap_resource”.
> Remove also a few error messages which became unnecessary with this
> software refactoring.
>
Markus, Thank you very much!yes, your comments is better. I will send
the patch v2. Thanks again!

>
> Will any more contributors get into the development mood to achieve
> similar collateral evolution by the means of the semantic patch language?
> Would you like to increase applications of the Coccinelle software?
>
I want, but currently I don't have much free time, sorry!

BR,
Dejin
> Regards,
> Markus