simplify with devm
Subsystems (3)
v2 cover simplify with devm
Makes probe simpler and easier to reason about.
v2: Just resent.
Rosen Penev (2):
net: mdio-ipq8064: use platform_get_resource
net: mdio-ipq8064: remove _remove function
drivers/net/mdio/mdio-ipq8064.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
Signature · 1 line
2.47.0
PATCH v2 1/2 net: mdio-ipq8064: use platform_get_resource
There's no need to get the of_node explicitly. platform_get_resource already does this.
--- drivers/net/mdio/mdio-ipq8064.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/mdio/mdio-ipq8064.c +4 -3
@@ -111,15 +111,16 @@ ipq8064_mdio_probe(struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;struct ipq8064_mdio *priv; -struct resource res; +struct resource *res;struct mii_bus *bus;void __iomem *base;int ret; -if (of_address_to_resource (np,0 , &res)) + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res)return -ENOMEM ; - base =devm_ioremap (&pdev->dev, res.start,resource_size (&res)); + base =devm_ioremap (&pdev->dev, res->start,resource_size (res));if (!base)return -ENOMEM ;
Signature · 1 line
2.47.0
PATCH v2 2/2 net: mdio-ipq8064: remove _remove function
In reply to Rosen PenevChange of_mdiobus_register to devm_mdiobus_register as devm allows removing the _remove function as well as slightly cleaning up the probe function.
Regular mdiobus_register is fine here as the platform device's of_node is used. Removes two variables from _probe.
--- drivers/net/mdio/mdio-ipq8064.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
drivers/net/mdio/mdio-ipq8064.c +1 -16
@@ -109,12 +109,10 @@ static const struct regmap_config ipq8064_mdio_regmap_config = {static int ipq8064_mdio_probe (struct platform_device *pdev) { -struct device_node *np = pdev->dev.of_node;struct ipq8064_mdio *priv;struct resource *res;struct mii_bus *bus;void __iomem *base; -int ret; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)
@@ -140,19 +138,7 @@ ipq8064_mdio_probe(struct platform_device *pdev)if (IS_ERR (priv->base))return PTR_ERR (priv->base); - ret =of_mdiobus_register (bus, np); -if (ret) -return ret; - -platform_set_drvdata (pdev, bus); -return 0 ; -} - -static void ipq8064_mdio_remove (struct platform_device *pdev) -{ -struct mii_bus *bus =platform_get_drvdata (pdev); - -mdiobus_unregister (bus); +return devm_mdiobus_register (&pdev->dev, bus); }static const struct of_device_id ipq8064_mdio_dt_ids[] = {
@@ -163,7 +149,6 @@ MODULE_DEVICE_TABLE(of, ipq8064_mdio_dt_ids);static struct platform_driver ipq8064_mdio_driver = { .probe = ipq8064_mdio_probe, - .remove = ipq8064_mdio_remove, .driver = { .name ="ipq8064-mdio" , .of_match_table = ipq8064_mdio_dt_ids,
Signature · 1 line
2.47.0
Heiner Kallweit
maintainerRe: [PATCH net-next 1/2] net: mdio-ipq8064: use platform_get_resource
In reply to Rosen PenevQuoted 22 lines · Rosen Penev
There's no need to get the
of_nodeexplicitly.platform_get_resourcealready does this.Signed-off-by Rosen Penev <[email protected]>--- drivers/net/mdio/mdio-ipq8064.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/net/mdio/mdio-ipq8064.c +1
-1@@ -111,15 +111,16 @@ ipq8064_mdio_probe(struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;struct ipq8064_mdio *priv; -struct resource res; +struct resource *res;struct mii_bus *bus;void __iomem *base;int ret;
drivers/net/mdio/mdio-ipq8064.c ipq8064_mdio_probe(struct platform_device *pdev) · line 126
Quoted 10 lines
drivers/net/mdio/mdio-ipq8064.c +3
-2-if (of_address_to_resource (np,0 , &res)) + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res)return -ENOMEM ; - base =devm_ioremap (&pdev->dev, res.start,resource_size (&res)); + base =devm_ioremap (&pdev->dev, res->start,resource_size (res));if (!base)return -ENOMEM ;
Why not directly switching to devm_platform_get_and_ioremap_resource()?
Re: [PATCH net-next 1/2] net: mdio-ipq8064: use platform_get_resource
Quoted 29 lines · Heiner Kallweit
Quoted 27 lines · Rosen Penev
There's no need to get the
of_nodeexplicitly.platform_get_resourcealready does this.Signed-off-by Rosen Penev <[email protected]>--- drivers/net/mdio/mdio-ipq8064.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/net/mdio/mdio-ipq8064.c +3
-2@@ -111,15 +111,16 @@ ipq8064_mdio_probe(struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;struct ipq8064_mdio *priv; -struct resource res; +struct resource *res;struct mii_bus *bus;void __iomem *base;int ret; -if (of_address_to_resource (np,0 , &res)) + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res)return -ENOMEM ;
Quoted 7 lines
drivers/net/mdio/mdio-ipq8064.c ipq8064_mdio_probe(struct platform_device *pdev) · line 126
Quoted 5 lines
drivers/net/mdio/mdio-ipq8064.c +1
-1- base =devm_ioremap (&pdev->dev, res.start,resource_size (&res)); + base =devm_ioremap (&pdev->dev, res->start,resource_size (res));if (!base)return -ENOMEM ;Why not directly switching to
devm_platform_get_and_ioremap_resource()?
Because that is not the same.
devm_platform_get_and_ioremap_resource is
platform_get_resource + request_memory_region + ioremap
The issue here is the second. This driver (well, platform really) uses overlapping memory regions and so request_memory_region will fail.
Andrew Lunn
maintainerQuoted 1 line · Rosen Penev
Makes probe simpler and easier to reason about.
Hi Rosen
For all future patches, please say either:
Test on real hardware.
or
Compile tested only
We need to know this to help determine the risk of accepting the patches. Clearly something you have tested is a lot lower risk than something which is only compile tested.
Andrew