Skip to contentSkip to conversation

net: hisilicon: unmap IO resources when cleanup

PATCH New Sheng Yong 3 participants 3 messages Nov 29, 2014

Subsystems (2)
lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

PATCH 1/1 net: hisilicon: unmap IO resources when cleanup

Unmap IO resources if the driver initailization failed or the driver is unmounted.

---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +10 -4
index 0ffdcd3..3399ce6 100644
@@ -917,26 +917,26 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	priv->ctrl_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(priv->ctrl_base)) {
 		ret = PTR_ERR(priv->ctrl_base);
-		goto out_free_netdev;
+		goto out_base;
 	}
 
 	priv->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(priv->clk)) {
 		netdev_err(ndev, "failed to get clk\n");
 		ret = -ENODEV;
-		goto out_free_netdev;
+		goto out_ctrl_base;
 	}
 
 	ret = clk_prepare_enable(priv->clk);
 	if (ret < 0) {
 		netdev_err(ndev, "failed to enable clk %d\n", ret);
-		goto out_free_netdev;
+		goto out_ctrl_base;
 	}
 
 	bus = mdiobus_alloc();
 	if (bus == NULL) {
 		ret = -ENOMEM;
-		goto out_free_netdev;
+		goto out_ctrl_base;
 	}
 
 	bus->priv = priv;
@@ -1019,6 +1019,10 @@ err_mdiobus:
 	mdiobus_unregister(bus);
 err_free_mdio:
 	mdiobus_free(bus);
+out_base:
+        iounmap(priv->base);
+out_ctrl_base:
+	iounmap(priv->ctrl_base);
 out_free_netdev:
 	free_netdev(ndev);
 
@@ -1038,6 +1042,8 @@ static int hix5hd2_dev_remove(struct platform_device *pdev)
 	hix5hd2_destroy_hw_desc_queue(priv);
 	of_node_put(priv->phy_node);
 	cancel_work_sync(&priv->tx_timeout_task);
+	iounmap(priv->base);
+	iounmap(priv->ctrl_base);
 	free_netdev(ndev);
 
 	return 0;
Signature · 1 line
1.8.3.4
#1 lore raw

PATCH 1/1 net: hisilicon: unmap IO resources when cleanup

Hi, Sheng Yong,

A question for you,

Quoted 13 lines · Sheng Yong

Unmap IO resources if the driver initailization failed or the driver is unmounted.

---
  drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +0 -0
index 0ffdcd3..3399ce6 100644

drivers/net/ethernet/hisilicon/hix5hd2_gmac.c static int hix5hd2_dev_probe(struct platform_device *pdev) · line 920

Quoted 5 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +1 -1
@@ -917,26 +917,26 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
  	priv->ctrl_base = devm_ioremap_resource(dev, res);
  	if (IS_ERR(priv->ctrl_base)) {
  		ret = PTR_ERR(priv->ctrl_base);
-		goto out_free_netdev;
+		goto out_base;

As i know we don't need to do anything but return error code from probe when using devm_xxx for getting resource.
What's the idea to io-unmap explicitly here?

Thanks,
Orson

Quoted 45 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +9 -3
  	}
 
  	priv->clk = devm_clk_get(&pdev->dev, NULL);
  	if (IS_ERR(priv->clk)) {
  		netdev_err(ndev, "failed to get clk\n");
  		ret = -ENODEV;
-		goto out_free_netdev;
+		goto out_ctrl_base;
  	}
 
  	ret = clk_prepare_enable(priv->clk);
  	if (ret < 0) {
  		netdev_err(ndev, "failed to enable clk %d\n", ret);
-		goto out_free_netdev;
+		goto out_ctrl_base;
  	}
 
  	bus = mdiobus_alloc();
  	if (bus == NULL) {
  		ret = -ENOMEM;
-		goto out_free_netdev;
+		goto out_ctrl_base;
  	}
 
  	bus->priv = priv;
@@ -1019,6 +1019,10 @@ err_mdiobus:
  	mdiobus_unregister(bus);
  err_free_mdio:
  	mdiobus_free(bus);
+out_base:
+        iounmap(priv->base);
+out_ctrl_base:
+	iounmap(priv->ctrl_base);
  out_free_netdev:
  	free_netdev(ndev);
 
@@ -1038,6 +1042,8 @@ static int hix5hd2_dev_remove(struct platform_device *pdev)
  	hix5hd2_destroy_hw_desc_queue(priv);
  	of_node_put(priv->phy_node);
  	cancel_work_sync(&priv->tx_timeout_task);
+	iounmap(priv->base);
+	iounmap(priv->ctrl_base);
  	free_netdev(ndev);
 
  	return 0;
#2 lore raw

PATCH 1/1 net: hisilicon: unmap IO resources when cleanup

Quoted 9 lines · On Saturday 29 November 2014 10:50:02 Orson Zhai wrote:
Quoted 8 lines · Sheng Yong

Unmap IO resources if the driver initailization failed or the driver is unmounted.

---
  drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
Quoted 14 lines

drivers/net/ethernet/hisilicon/hix5hd2_gmac.c static int hix5hd2_dev_probe(struct platform_device *pdev) · line 920

Quoted 10 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +1 -1
index 0ffdcd3..3399ce6 100644
@@ -917,26 +917,26 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
      priv->ctrl_base = devm_ioremap_resource(dev, res);
      if (IS_ERR(priv->ctrl_base)) {
              ret = PTR_ERR(priv->ctrl_base);
-             goto out_free_netdev;
+             goto out_base;

As i know we don't need to do anything but return error code from probe when using devm_xxx for getting resource.
What's the idea to io-unmap explicitly here?

I think it's actually a bug to pair devm_ioremap() with iounmap, since the iounmap will be done twice then, and that causes undefined behavior.

In cases where you have to unmap something explicitly, devm_iounmap should be used, but in this case the patch seems entirely wrong, the code without the patch looks correct.

Arnd