lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <e1fd0cc1fd865e58af713c92f09251e6180c1636.1672865629.git.christophe.jaillet@wanadoo.fr>
Date:   Wed,  4 Jan 2023 22:05:33 +0100
From:   Christophe JAILLET <christophe.jaillet@...adoo.fr>
To:     "David S . Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>
Cc:     linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
        netdev@...r.kernel.org,
        Christophe JAILLET <christophe.jaillet@...adoo.fr>
Subject: [PATCH net-next 2/3] ezchip: Switch to some devm_ function to simplify code

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@...adoo.fr>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ