public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: isubramanian@apm.com (Iyappan Subramanian)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH net-next 04/10] drivers: net: xgene: Fix error deconstruction path
Date: Fri, 29 Jul 2016 17:33:57 -0700	[thread overview]
Message-ID: <1469838843-19943-5-git-send-email-isubramanian@apm.com> (raw)
In-Reply-To: <1469838843-19943-1-git-send-email-isubramanian@apm.com>

Since register_netdev() call in xgene_enet_probe() was moved down to
the end, it doesn't properly handle errors that may occur, by
deconstructing everything that was setup before the error occurred.

Signed-off-by: Iyappan Subramanian <isubramanian@apm.com>
---
 drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 27 +++++++++++++++++-------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
index 6fc5698..d05f999 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -1643,8 +1643,8 @@ static int xgene_enet_probe(struct platform_device *pdev)
 	}
 #endif
 	if (!pdata->enet_id) {
-		free_netdev(ndev);
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err;
 	}
 
 	ret = xgene_enet_get_resources(pdata);
@@ -1667,7 +1667,7 @@ static int xgene_enet_probe(struct platform_device *pdev)
 
 	ret = xgene_enet_init_hw(pdata);
 	if (ret)
-		goto err_netdev;
+		goto err;
 
 	link_state = pdata->mac_ops->link_state;
 	if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
@@ -1677,21 +1677,32 @@ static int xgene_enet_probe(struct platform_device *pdev)
 			ret = xgene_enet_mdio_config(pdata);
 		else
 			INIT_DELAYED_WORK(&pdata->link_work, link_state);
+
+		if (ret)
+			goto err1;
 	}
-	if (ret)
-		goto err;
 
 	xgene_enet_napi_add(pdata);
 	ret = register_netdev(ndev);
 	if (ret) {
 		netdev_err(ndev, "Failed to register netdev\n");
-		goto err;
+		goto err2;
 	}
 
 	return 0;
 
-err_netdev:
-	unregister_netdev(ndev);
+err2:
+	/*
+	 * If necessary, free_netdev() will call netif_napi_del() and undo
+	 * the effects of xgene_enet_napi_add()'s calls to netif_napi_add().
+	 */
+
+	if (pdata->mdio_driver)
+		xgene_enet_phy_disconnect(pdata);
+	else if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII)
+		xgene_enet_mdio_remove(pdata);
+err1:
+	xgene_enet_delete_desc_rings(pdata);
 err:
 	free_netdev(ndev);
 	return ret;
-- 
1.9.1

  parent reply	other threads:[~2016-07-30  0:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30  0:33 [PATCH net-next 00/10] Fix warning and issues Iyappan Subramanian
2016-07-30  0:33 ` [PATCH net-next 01/10] drivers: net: xgene: Fix kbuild warning Iyappan Subramanian
2016-07-30  9:13   ` Arnd Bergmann
2016-07-30  0:33 ` [PATCH net-next 02/10] drivers: net: xgene: fix: Add dma_unmap_single Iyappan Subramanian
2016-07-30  0:33 ` [PATCH net-next 03/10] drivers: net: xgene: fix: Delete descriptor rings and buffer pools Iyappan Subramanian
2016-07-30  0:33 ` Iyappan Subramanian [this message]
2016-07-30  0:33 ` [PATCH net-next 05/10] drivers: net: xgene: Fix RSS indirection table fields Iyappan Subramanian
2016-07-30  0:33 ` [PATCH net-next 06/10] drivers: net: xgene: Change port init sequence Iyappan Subramanian
2016-07-30  0:34 ` [PATCH net-next 07/10] drivers: net: xgene: XFI PCS reset when link is down Iyappan Subramanian
2016-07-30  0:34 ` [PATCH net-next 08/10] drivers: net: xgene: Poll link status via GPIO Iyappan Subramanian
2016-07-30  1:56   ` kbuild test robot
2016-07-30  4:32   ` kbuild test robot
2016-07-30  5:42   ` kbuild test robot
2016-08-01  5:39   ` Quan Nguyen
2016-07-30  0:34 ` [PATCH net-next 09/10] dtb: xgene: Add rxlos-gpios property Iyappan Subramanian
2016-07-30  0:34 ` [PATCH net-next 10/10] Documentation: dtb: xgene: Add rxlos GPIO mapping Iyappan Subramanian
2016-08-01 16:35   ` Rob Herring
2016-08-02  6:03     ` Quan Nguyen
2016-07-30  3:12 ` [PATCH net-next 00/10] Fix warning and issues David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469838843-19943-5-git-send-email-isubramanian@apm.com \
    --to=isubramanian@apm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox