Skip to contentSkip to conversation

net/phy/mdio-mscc-miim: Adjustments for mscc_miim_probe()

PATCH Superseded Markus Elfring 3 participants 12 messages Sep 20, 2019 – Sep 27, 2019

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

cover net/phy/mdio-mscc-miim: Adjustments for mscc_miim_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 20 Sep 2019 20:52:25 +0200

Two update suggestions were taken into account

from static source code analysis.

Markus Elfring (2):
Use devm_platform_ioremap_resource()
Move the setting of mii_bus structure members

 drivers/net/phy/mdio-mscc-miim.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

--
2.23.0

#1 lore raw

PATCH 1/2 net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 20 Sep 2019 20:20:34 +0200

Simplify this function implementation by using a known wrapper function.

This issue was detected by using the Coccinelle software.

---
 drivers/net/phy/mdio-mscc-miim.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +5 -13
index badbc99bedd3..b36fe81b6e6d 100644
@@ -115,15 +115,10 @@ static int mscc_miim_reset(struct mii_bus *bus)
 
 static int mscc_miim_probe(struct platform_device *pdev)
 {
-	struct resource *res;
 	struct mii_bus *bus;
 	struct mscc_miim_dev *dev;
 	int ret;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
-
 	bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*dev));
 	if (!bus)
 		return -ENOMEM;
@@ -136,19 +131,16 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	bus->parent = &pdev->dev;
 
 	dev = bus->priv;
-	dev->regs = devm_ioremap_resource(&pdev->dev, res);
+	dev->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(dev->regs)) {
 		dev_err(&pdev->dev, "Unable to map MIIM registers\n");
 		return PTR_ERR(dev->regs);
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (res) {
-		dev->phy_regs = devm_ioremap_resource(&pdev->dev, res);
-		if (IS_ERR(dev->phy_regs)) {
-			dev_err(&pdev->dev, "Unable to map internal phy registers\n");
-			return PTR_ERR(dev->phy_regs);
-		}
+	dev->phy_regs = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(dev->phy_regs)) {
+		dev_err(&pdev->dev, "Unable to map internal phy registers\n");
+		return PTR_ERR(dev->phy_regs);
 	}
 
 	ret = of_mdiobus_register(bus, pdev->dev.of_node);

--
2.23.0

maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

Quoted 8 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 20 Sep 2019 20:20:34 +0200

Simplify this function implementation by using a known wrapper function.

This issue was detected by using the Coccinelle software.

Andrew

#3 lore raw

Re: [1/2] net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

Quoted 1 line
Quoted 1 line

Simplify this function implementation by using a known wrapper function.

…

Quoted 1 line

Does this feedback indicate also an agreement for the detail if the mapping of internal phy registers would be a required operation? (Would such a resource allocation eventually be optional?)
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/phy/mdio-mscc-miim.c?id=f41def397161053eb0d3ed6861ef65985efbf293#n145
https://elixir.bootlin.com/linux/v5.3.1/source/drivers/net/phy/mdio-mscc-miim.c#L145

Regards,
Markus

#4 lore raw

Re: [1/2] net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

Quoted 7 lines · Markus Elfring
Quoted 1 line
Quoted 1 line

Simplify this function implementation by using a known wrapper function.

…

Quoted 1 line

Does this feedback indicate also an agreement for the detail if the mapping of internal phy registers would be a required operation? (Would such a resource allocation eventually be optional?)

It is optional.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

Re: [1/2] net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

Quoted 5 lines
Quoted 3 lines

Does this feedback indicate also an agreement for the detail if the mapping of internal phy registers would be a required operation? (Would such a resource allocation eventually be optional?)

It is optional.

Would you like to integrate an other patch variant then?

Regards,
Markus

#6 lore raw

Re: [1/2] net/phy/mdio-mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

Quoted 8 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines

Does this feedback indicate also an agreement for the detail if the mapping of internal phy registers would be a required operation? (Would such a resource allocation eventually be optional?)

It is optional.

Would you like to integrate an other patch variant then?

You have to ensure it stays optional. Also, adjust the subject so it uses the correct prefix.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

v2 cover net: phy: mscc-miim: Adjustments for mscc_miim_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 27 Sep 2019 09:48:09 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use devm_platform_ioremap_resource()
Move the setting of mii_bus structure members

 drivers/net/phy/mdio-mscc-miim.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

--
2.23.0

#8 lore raw

PATCH v2 1/2 net: phy: mscc-miim: Use devm_platform_ioremap_resource() in mscc_miim_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 27 Sep 2019 09:24:03 +0200

Simplify this function implementation a bit by using a known wrapper function.

This issue was detected by using the Coccinelle software.

---

v2:
Alexandre Belloni pointed the need for adjustments out.
https://lore.kernel.org/r/[email protected]/

* The mapping of internal phy registers should be treated as optional.
* An other prefix would be preferred in the commit subject.

 drivers/net/phy/mdio-mscc-miim.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +1 -5
index badbc99bedd3..aabb13982251 100644
@@ -120,10 +120,6 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	struct mscc_miim_dev *dev;
 	int ret;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
-
 	bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*dev));
 	if (!bus)
 		return -ENOMEM;
@@ -136,7 +132,7 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	bus->parent = &pdev->dev;
 
 	dev = bus->priv;
-	dev->regs = devm_ioremap_resource(&pdev->dev, res);
+	dev->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(dev->regs)) {
 		dev_err(&pdev->dev, "Unable to map MIIM registers\n");
 		return PTR_ERR(dev->regs);

--
2.23.0

#9 lore raw

PATCH v2 2/2 net: phy: mscc-miim: Move the setting of mii_bus structure members in mscc_miim_probe()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Sep 2019 09:30:14 +0200

Move the modification of some members in the data structure “mii_bus” for the local variable “bus” directly before the call of
the function “of_mdiobus_register” so that this change will be performed only after previous resource allocations succeeded.

---

v2:
This suggestion was repeated based on the change for the previous update step.

 drivers/net/phy/mdio-mscc-miim.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +6 -7
index aabb13982251..a270f83bb207 100644
@@ -124,13 +124,6 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	if (!bus)
 		return -ENOMEM;
 
-	bus->name = "mscc_miim";
-	bus->read = mscc_miim_read;
-	bus->write = mscc_miim_write;
-	bus->reset = mscc_miim_reset;
-	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
-	bus->parent = &pdev->dev;
-
 	dev = bus->priv;
 	dev->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(dev->regs)) {
@@ -147,6 +140,12 @@ static int mscc_miim_probe(struct platform_device *pdev)
 		}
 	}
 
+	bus->name = "mscc_miim";
+	bus->read = mscc_miim_read;
+	bus->write = mscc_miim_write;
+	bus->reset = mscc_miim_reset;
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
+	bus->parent = &pdev->dev;
 	ret = of_mdiobus_register(bus, pdev->dev.of_node);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret);

--
2.23.0

#10 lore raw

PATCH 2/2 net/phy/mdio-mscc-miim: Move the setting of mii_bus structure members in mscc_miim_probe()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 20 Sep 2019 20:42:42 +0200

Move the modification of some members in the data structure “mii_bus” for the local variable “bus” directly before the call of
the function “of_mdiobus_register” so that this change will be performed only after previous resource allocations succeeded.

---
 drivers/net/phy/mdio-mscc-miim.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +6 -7
index b36fe81b6e6d..c46e0c78402e 100644
@@ -123,13 +123,6 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	if (!bus)
 		return -ENOMEM;
 
-	bus->name = "mscc_miim";
-	bus->read = mscc_miim_read;
-	bus->write = mscc_miim_write;
-	bus->reset = mscc_miim_reset;
-	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
-	bus->parent = &pdev->dev;
-
 	dev = bus->priv;
 	dev->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(dev->regs)) {
@@ -143,6 +136,12 @@ static int mscc_miim_probe(struct platform_device *pdev)
 		return PTR_ERR(dev->phy_regs);
 	}
 
+	bus->name = "mscc_miim";
+	bus->read = mscc_miim_read;
+	bus->write = mscc_miim_write;
+	bus->reset = mscc_miim_reset;
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
+	bus->parent = &pdev->dev;
 	ret = of_mdiobus_register(bus, pdev->dev.of_node);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret);

--
2.23.0

maintainer
#11 lore raw

Re: [PATCH 2/2] net/phy/mdio-mscc-miim: Move the setting of mii_bus structure members in mscc_miim_probe()

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 20 Sep 2019 20:42:42 +0200

Move the modification of some members in the data structure “mii_bus” for the local variable “bus” directly before the call of
the function “of_mdiobus_register” so that this change will be performed only after previous resource allocations succeeded.

Hi Markus

I'm not sure it is worth making this change. The resource allocations succeeds 99.9999% of the time. It is a chunk of MMIO, not some gpio, or i2c device which might give us EPROBE_DEFERRED. So we are not wasting anything in reality.

Andrew