[PATCH net-next 2/3] ezchip: Switch to some devm_ function to simplify code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



devm_alloc_etherdev() and devm_register_netdev() can be used to simplify
code.

Now the error handling path of the probe and the remove function are
useless and can be removed completely.

Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
 drivers/net/ethernet/ezchip/nps_enet.c | 42 ++++++--------------------
 1 file changed, 9 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/ezchip/nps_enet.c b/drivers/net/ethernet/ezchip/nps_enet.c
index 6389c6b5005c..21e230150104 100644
--- a/drivers/net/ethernet/ezchip/nps_enet.c
+++ b/drivers/net/ethernet/ezchip/nps_enet.c
@@ -579,7 +579,7 @@ static s32 nps_enet_probe(struct platform_device *pdev)
 	if (!dev->of_node)
 		return -ENODEV;
 
-	ndev = alloc_etherdev(sizeof(struct nps_enet_priv));
+	ndev = devm_alloc_etherdev(dev, sizeof(struct nps_enet_priv));
 	if (!ndev)
 		return -ENOMEM;
 
@@ -594,10 +594,8 @@ static s32 nps_enet_probe(struct platform_device *pdev)
 	ndev->flags &= ~IFF_MULTICAST;
 
 	priv->regs_base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(priv->regs_base)) {
-		err = PTR_ERR(priv->regs_base);
-		goto out_netdev;
-	}
+	if (IS_ERR(priv->regs_base))
+		return PTR_ERR(priv->regs_base);
 	dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs_base);
 
 	/* set kernel MAC address to dev */
@@ -607,41 +605,20 @@ static s32 nps_enet_probe(struct platform_device *pdev)
 
 	/* Get IRQ number */
 	priv->irq = platform_get_irq(pdev, 0);
-	if (priv->irq < 0) {
-		err = -ENODEV;
-		goto out_netdev;
-	}
+	if (priv->irq < 0)
+		return -ENODEV;
 
 	netif_napi_add_weight(ndev, &priv->napi, nps_enet_poll,
 			      NPS_ENET_NAPI_POLL_WEIGHT);
 
 	/* Register the driver. Should be the last thing in probe */
-	err = register_netdev(ndev);
-	if (err) {
-		dev_err(dev, "Failed to register ndev for %s, err = 0x%08x\n",
-			ndev->name, (s32)err);
-		goto out_netif_api;
-	}
+	err = devm_register_netdev(dev, ndev);
+	if (err)
+		return dev_err_probe(dev, err, "Failed to register ndev for %s\n",
+				     ndev->name);
 
 	dev_info(dev, "(rx/tx=%d)\n", priv->irq);
 	return 0;
-
-out_netif_api:
-out_netdev:
-	free_netdev(ndev);
-
-	return err;
-}
-
-static s32 nps_enet_remove(struct platform_device *pdev)
-{
-	struct net_device *ndev = platform_get_drvdata(pdev);
-	struct nps_enet_priv *priv = netdev_priv(ndev);
-
-	unregister_netdev(ndev);
-	free_netdev(ndev);
-
-	return 0;
 }
 
 static const struct of_device_id nps_enet_dt_ids[] = {
@@ -652,7 +629,6 @@ MODULE_DEVICE_TABLE(of, nps_enet_dt_ids);
 
 static struct platform_driver nps_enet_driver = {
 	.probe = nps_enet_probe,
-	.remove = nps_enet_remove,
 	.driver = {
 		.name = DRV_NAME,
 		.of_match_table  = nps_enet_dt_ids,
-- 
2.34.1




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux