Skip to contentSkip to conversation

net: ag71xx: get reset control using devm api

PATCH In review Rosen Penev 3 participants 5 messages Aug 26, 2024 – Aug 30, 2024

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

PATCH v4 1/1 net: ag71xx: get reset control using devm api

Currently, the of variant is missing reset_control_put in error paths. The devm variant does not require it.

Allows removing mdio_reset from the struct as it is not used outside the function.

---
v2: don't call after ag71xx_mdio_probe. Already done.
v3: use devm instead.
v4: resend to bump the CI

 drivers/net/ethernet/atheros/ag71xx.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/atheros/ag71xx.c +7 -7
index 89cd001b385f..d81aa0ccd572 100644
@@ -379,7 +379,6 @@ struct ag71xx {
 	u32 fifodata[3];
 	int mac_idx;
 
-	struct reset_control *mdio_reset;
 	struct clk *clk_mdio;
 };
 
@@ -683,6 +682,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	struct device *dev = &ag->pdev->dev;
 	struct net_device *ndev = ag->ndev;
 	static struct mii_bus *mii_bus;
+	struct reset_control *mdio_reset;
 	struct device_node *np, *mnp;
 	int err;
 
@@ -698,10 +698,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	if (!mii_bus)
 		return -ENOMEM;
 
-	ag->mdio_reset = of_reset_control_get_exclusive(np, "mdio");
-	if (IS_ERR(ag->mdio_reset)) {
+	mdio_reset = devm_reset_control_get_exclusive(dev, "mdio");
+	if (IS_ERR(mdio_reset)) {
 		netif_err(ag, probe, ndev, "Failed to get reset mdio.\n");
-		return PTR_ERR(ag->mdio_reset);
+		return PTR_ERR(mdio_reset);
 	}
 
 	mii_bus->name = "ag71xx_mdio";
@@ -712,10 +712,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	mii_bus->parent = dev;
 	snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%s.%d", np->name, ag->mac_idx);
 
-	if (!IS_ERR(ag->mdio_reset)) {
-		reset_control_assert(ag->mdio_reset);
+	if (!IS_ERR(mdio_reset)) {
+		reset_control_assert(mdio_reset);
 		msleep(100);
-		reset_control_deassert(ag->mdio_reset);
+		reset_control_deassert(mdio_reset);
 		msleep(200);
 	}
 
Signature · 1 line
2.46.0
maintainer
#1 lore raw

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 685

Quoted 11 lines · On Mon, 26 Aug 2024 14:21:57 -0700 Rosen Penev wrote:

Currently, the of variant is missing reset_control_put in error paths. The devm variant does not require it.

Allows removing mdio_reset from the struct as it is not used outside the function.

drivers/net/ethernet/atheros/ag71xx.c +1 -0
@@ -683,6 +682,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	struct device *dev = &ag->pdev->dev;
 	struct net_device *ndev = ag->ndev;
 	static struct mii_bus *mii_bus;
+	struct reset_control *mdio_reset;

nit: maintain the longest to shortest ordering of the variables (sorted by line length not type length)

Quoted 18 lines
drivers/net/ethernet/atheros/ag71xx.c +3 -3
 	struct device_node *np, *mnp;
 	int err;
 
@@ -698,10 +698,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	if (!mii_bus)
 		return -ENOMEM;
 
-	ag->mdio_reset = of_reset_control_get_exclusive(np, "mdio");
-	if (IS_ERR(ag->mdio_reset)) {
+	mdio_reset = devm_reset_control_get_exclusive(dev, "mdio");
+	if (IS_ERR(mdio_reset)) {
 		netif_err(ag, probe, ndev, "Failed to get reset mdio.\n");
-		return PTR_ERR(ag->mdio_reset);
+		return PTR_ERR(mdio_reset);
 	}
 
 	mii_bus->name = "ag71xx_mdio";

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 715

Quoted 6 lines
drivers/net/ethernet/atheros/ag71xx.c +1 -2
@@ -712,10 +712,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
 	mii_bus->parent = dev;
 	snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%s.%d", np->name, ag->mac_idx);
 
-	if (!IS_ERR(ag->mdio_reset)) {
-		reset_control_assert(ag->mdio_reset);
+	if (!IS_ERR(mdio_reset)) {

Are you planning to follow up to remove this check? Would be nice to do that as second patch in the same series

Quoted 7 lines
drivers/net/ethernet/atheros/ag71xx.c +2 -1
+		reset_control_assert(mdio_reset);
 		msleep(100);
-		reset_control_deassert(ag->mdio_reset);
+		reset_control_deassert(mdio_reset);
 		msleep(200);
 	}
 
#2 lore raw
Quoted 38 lines · Jakub Kicinski

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 685

Quoted 11 lines · On Mon, 26 Aug 2024 14:21:57 -0700 Rosen Penev wrote:

Currently, the of variant is missing reset_control_put in error paths. The devm variant does not require it.

Allows removing mdio_reset from the struct as it is not used outside the function.

drivers/net/ethernet/atheros/ag71xx.c +1 -0
@@ -683,6 +682,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      struct device *dev = &ag->pdev->dev;
      struct net_device *ndev = ag->ndev;
      static struct mii_bus *mii_bus;
+     struct reset_control *mdio_reset;

nit: maintain the longest to shortest ordering of the variables (sorted by line length not type length)

Quoted 21 lines
drivers/net/ethernet/atheros/ag71xx.c +3 -3
      struct device_node *np, *mnp;
      int err;
 
@@ -698,10 +698,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      if (!mii_bus)
              return -ENOMEM;
 
-     ag->mdio_reset = of_reset_control_get_exclusive(np, "mdio");
-     if (IS_ERR(ag->mdio_reset)) {
+     mdio_reset = devm_reset_control_get_exclusive(dev, "mdio");
+     if (IS_ERR(mdio_reset)) {
              netif_err(ag, probe, ndev, "Failed to get reset mdio.\n");
-             return PTR_ERR(ag->mdio_reset);
+             return PTR_ERR(mdio_reset);
      }
 
      mii_bus->name = "ag71xx_mdio";
@@ -712,10 +712,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      mii_bus->parent = dev;
      snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%s.%d", np->name, ag->mac_idx);
 
Quoted 6 lines

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 715

Quoted 3 lines
drivers/net/ethernet/atheros/ag71xx.c +1 -2
-     if (!IS_ERR(ag->mdio_reset)) {
-             reset_control_assert(ag->mdio_reset);
+     if (!IS_ERR(mdio_reset)) {

Are you planning to follow up to remove this check? Would be nice to do that as second patch in the same series

I actually have no idea why this is here. I assume it's some mistake. I don't think it's meant to be optional...

Quoted 9 lines
Quoted 8 lines
drivers/net/ethernet/atheros/ag71xx.c +2 -1
+             reset_control_assert(mdio_reset);
              msleep(100);
-             reset_control_deassert(ag->mdio_reset);
+             reset_control_deassert(mdio_reset);
              msleep(200);
      }
 
#3 lore raw
Quoted 42 lines · Jakub Kicinski
Quoted 41 lines · On Mon, 26 Aug 2024 14:21:57 -0700 Rosen Penev wrote:

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 685

Quoted 11 lines

Currently, the of variant is missing reset_control_put in error paths. The devm variant does not require it.

Allows removing mdio_reset from the struct as it is not used outside the function.

drivers/net/ethernet/atheros/ag71xx.c +1 -0
@@ -683,6 +682,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      struct device *dev = &ag->pdev->dev;
      struct net_device *ndev = ag->ndev;
      static struct mii_bus *mii_bus;
+     struct reset_control *mdio_reset;

nit: maintain the longest to shortest ordering of the variables (sorted by line length not type length)

Quoted 24 lines
drivers/net/ethernet/atheros/ag71xx.c +3 -3
      struct device_node *np, *mnp;
      int err;
 
@@ -698,10 +698,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      if (!mii_bus)
              return -ENOMEM;
 
-     ag->mdio_reset = of_reset_control_get_exclusive(np, "mdio");
-     if (IS_ERR(ag->mdio_reset)) {
+     mdio_reset = devm_reset_control_get_exclusive(dev, "mdio");
 
 
 
+     if (IS_ERR(mdio_reset)) {
              netif_err(ag, probe, ndev, "Failed to get reset mdio.\n");
-             return PTR_ERR(ag->mdio_reset);
+             return PTR_ERR(mdio_reset);
      }

      mii_bus->name = "ag71xx_mdio";
drivers/net/ethernet/atheros/ag71xx.c +0 -0
@@ -712,10 +712,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      mii_bus->parent = dev;
      snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%s.%d", np->name, ag->mac_idx);
 
Quoted 8 lines
Quoted 6 lines

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 715

Quoted 3 lines
drivers/net/ethernet/atheros/ag71xx.c +1 -2
-     if (!IS_ERR(ag->mdio_reset)) {
-             reset_control_assert(ag->mdio_reset);
+     if (!IS_ERR(mdio_reset)) {

Are you planning to follow up to remove this check? Would be nice to do that as second patch in the same series

I actually have no idea why this is here. I assume it's some mistake. I don't think it's meant to be optional...

{devm,of}_reset_control_get_exclusive() will return an error if the OF node is missing. If it should be optional, it should be devm_reset_control_get_optional_exclusive(), which would return NULL if it is missing.

The equivalent driver used in OpenWrt does explicitly make it
optional. https://github.com/openwrt/openwrt/blob/4646aa169986036772b9f75393c08508d20ddf8b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c#L1532,
while the mac_reset is mandatory. They might have a reason for that or
maybe only heritage from Atheros AG7100 driver.

Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 720

Quoted 7 lines
drivers/net/ethernet/atheros/ag71xx.c +2 -1
+             reset_control_assert(mdio_reset);
              msleep(100);
-             reset_control_deassert(ag->mdio_reset);
+             reset_control_deassert(mdio_reset);
              msleep(200);
      }

Regards,

Luiz

#4 lore raw
Quoted 49 lines · Luiz Angelo Daros de Luca
Quoted 49 lines · Jakub Kicinski
Quoted 47 lines · On Mon, 26 Aug 2024 14:21:57 -0700 Rosen Penev wrote:

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 685

Quoted 11 lines

Currently, the of variant is missing reset_control_put in error paths. The devm variant does not require it.

Allows removing mdio_reset from the struct as it is not used outside the function.

drivers/net/ethernet/atheros/ag71xx.c +1 -0
@@ -683,6 +682,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      struct device *dev = &ag->pdev->dev;
      struct net_device *ndev = ag->ndev;
      static struct mii_bus *mii_bus;
+     struct reset_control *mdio_reset;

nit: maintain the longest to shortest ordering of the variables (sorted by line length not type length)

Quoted 21 lines
drivers/net/ethernet/atheros/ag71xx.c +3 -3
      struct device_node *np, *mnp;
      int err;
 
@@ -698,10 +698,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      if (!mii_bus)
              return -ENOMEM;
 
-     ag->mdio_reset = of_reset_control_get_exclusive(np, "mdio");
-     if (IS_ERR(ag->mdio_reset)) {
+     mdio_reset = devm_reset_control_get_exclusive(dev, "mdio");
 
 
 
+     if (IS_ERR(mdio_reset)) {
              netif_err(ag, probe, ndev, "Failed to get reset mdio.\n");
-             return PTR_ERR(ag->mdio_reset);
+             return PTR_ERR(mdio_reset);
      }

      mii_bus->name = "ag71xx_mdio";

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 715

Quoted 6 lines
drivers/net/ethernet/atheros/ag71xx.c +1 -2
@@ -712,10 +712,10 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
      mii_bus->parent = dev;
      snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%s.%d", np->name, ag->mac_idx);
 
-     if (!IS_ERR(ag->mdio_reset)) {
-             reset_control_assert(ag->mdio_reset);
+     if (!IS_ERR(mdio_reset)) {

Are you planning to follow up to remove this check? Would be nice to do that as second patch in the same series

Quoted 7 lines
Quoted 2 lines

I actually have no idea why this is here. I assume it's some mistake. I don't think it's meant to be optional...

{devm,of}_reset_control_get_exclusive() will return an error if the OF node is missing. If it should be optional, it should be devm_reset_control_get_optional_exclusive(), which would return NULL if it is missing.

I assume during upstreaming it was suggested to remove optional.

Quoted 3 lines

The equivalent driver used in OpenWrt does explicitly make it
optional. https://github.com/openwrt/openwrt/blob/4646aa169986036772b9f75393c08508d20ddf8b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c#L1532,

And also the wrong check (it should be NULL).

Quoted 14 lines

while the mac_reset is mandatory. They might have a reason for that or maybe only heritage from Atheros AG7100 driver.

Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/atheros/ag71xx.c static int ag71xx_mdio_probe(struct ag71xx *ag) · line 720

Quoted 7 lines
drivers/net/ethernet/atheros/ag71xx.c +2 -1
+             reset_control_assert(mdio_reset);
              msleep(100);
-             reset_control_deassert(ag->mdio_reset);
+             reset_control_deassert(mdio_reset);
              msleep(200);
      }

Regards,

Luiz