All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Mugunthan V N <mugunthanvnm@ti.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>,
	linux-omap@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>
Subject: [PATCH net v2 4/7] net: ethernet: ti: cpsw: fix of_node and phydev leaks
Date: Thu, 17 Nov 2016 17:40:01 +0100	[thread overview]
Message-ID: <1479400804-9847-5-git-send-email-johan@kernel.org> (raw)
In-Reply-To: <1479400804-9847-1-git-send-email-johan@kernel.org>

Make sure to drop references taken and deregister devices registered
during probe on probe errors (including deferred probe) and driver
unbind.

Specifically, PHY of-node references were never released and fixed-link
PHY devices were never deregistered.

Fixes: 9e42f715264f ("drivers: net: cpsw: add phy-handle parsing")
Fixes: 1f71e8c96fc6 ("drivers: net: cpsw: Add support for fixed-link
PHY")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/ti/cpsw.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 5d14abb06486..c3b78bc4fe58 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2443,6 +2443,41 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
 
 static void cpsw_remove_dt(struct platform_device *pdev)
 {
+	struct net_device *ndev = platform_get_drvdata(pdev);
+	struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
+	struct cpsw_platform_data *data = &cpsw->data;
+	struct device_node *node = pdev->dev.of_node;
+	struct device_node *slave_node;
+	int i = 0;
+
+	for_each_available_child_of_node(node, slave_node) {
+		struct cpsw_slave_data *slave_data = &data->slave_data[i];
+
+		if (strcmp(slave_node->name, "slave"))
+			continue;
+
+		if (of_phy_is_fixed_link(slave_node)) {
+			struct phy_device *phydev;
+
+			phydev = of_phy_find_device(slave_node);
+			if (phydev) {
+				fixed_phy_unregister(phydev);
+				/* Put references taken by
+				 * of_phy_find_device() and
+				 * of_phy_register_fixed_link().
+				 */
+				phy_device_free(phydev);
+				phy_device_free(phydev);
+			}
+		}
+
+		of_node_put(slave_data->phy_node);
+
+		i++;
+		if (i == data->slaves)
+			break;
+	}
+
 	of_platform_depopulate(&pdev->dev);
 }
 
-- 
2.7.3

  parent reply	other threads:[~2016-11-17 17:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-17 16:39 [PATCH net v2 0/7] net: cpsw: fix leaks and probe deferral Johan Hovold
2016-11-17 16:39 ` [PATCH net v2 1/7] net: ethernet: ti: cpsw: fix bad register access in probe error path Johan Hovold
2016-11-17 16:39 ` [PATCH net v2 2/7] net: ethernet: ti: cpsw: fix mdio device reference leak Johan Hovold
2016-11-17 16:40 ` [PATCH net v2 3/7] net: ethernet: ti: cpsw: fix deferred probe Johan Hovold
2016-11-17 16:40 ` Johan Hovold [this message]
2016-11-17 16:40 ` [PATCH net v2 5/7] net: ethernet: ti: cpsw: fix secondary-emac probe error path Johan Hovold
2016-11-17 16:40 ` [PATCH net v2 6/7] net: ethernet: ti: cpsw: add missing sanity check Johan Hovold
2016-11-17 16:40 ` [PATCH net v2 7/7] net: ethernet: ti: cpsw: fix fixed-link phy probe deferral Johan Hovold
2016-11-17 17:04   ` David Miller
2016-11-17 17:19     ` Johan Hovold
2016-11-18  9:33       ` Johan Hovold
2016-11-18 18:48       ` David Miller
2016-11-18 18:49 ` [PATCH net v2 0/7] net: cpsw: fix leaks and " 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=1479400804-9847-5-git-send-email-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=grygorii.strashko@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mugunthanvnm@ti.com \
    --cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.