From 1cd9632166b2863dfe5bebe8f19ce085cf9fb754 Mon Sep 17 00:00:00 2001 From: Reece R. Pollack Date: Mon, 16 Feb 2015 14:35:36 -0500 Subject: net: keystone: Fix memory leak in CPSW ALE configuration Prior to this patch, the CPSW ALE context was created when the first interface on a device was opened, but it was not destroyed when the last interface was closed (it was stopped instead). This resulted in a memory leak. This patch corrects this. Also, the ALE Slaves were being shut down after the ALE context was being destroyed. This could result in a NULL pointer reference. This patch fixes this too. Finally, the ALE reference count in keystone_xgess.c was a non-atomic integer, while the other modules used an atomic. This patch fixes this and includes some minor restructuring so the code looks more like the other two modules. Signed-off-by: Reece R. Pollack --- drivers/net/ethernet/ti/keystone_ethss2.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/net/ethernet/ti/keystone_ethss2.c') diff --git a/drivers/net/ethernet/ti/keystone_ethss2.c b/drivers/net/ethernet/ti/keystone_ethss2.c index f334bdb3ab5..5560d6e2c00 100644 --- a/drivers/net/ethernet/ti/keystone_ethss2.c +++ b/drivers/net/ethernet/ti/keystone_ethss2.c @@ -3510,11 +3510,13 @@ static int cpsw2_close(void *intf_priv, struct net_device *ndev) del_timer_sync(&cpsw_intf->timer); - if (atomic_dec_return(&cpsw_dev->ale_refcnt) == 0) - cpsw_ale_stop(cpsw_dev->ale); - for_each_slave(cpsw_intf, cpsw2_slave_stop, cpsw_intf); + if (atomic_dec_return(&cpsw_dev->ale_refcnt) == 0) { + cpsw_ale_destroy(cpsw_dev->ale); + cpsw_dev->ale = NULL; + } + if (!cpsw_dev->force_no_hwtstamp) netcp_unregister_rxhook(netcp, CPSW2_RXHOOK_ORDER, cpsw2_rx_hook, cpsw_intf); @@ -3538,8 +3540,6 @@ static int cpsw2_remove(struct netcp_device *netcp_device, void *inst_priv) of_node_put(cpsw_dev->interfaces); - cpsw_ale_destroy(cpsw_dev->ale); - list_for_each_entry_safe(cpsw_intf, tmp, &cpsw_dev->cpsw_intf_head, cpsw_intf_list) { netcp_delete_interface(netcp_device, cpsw_intf->ndev); -- cgit v1.2.3-54-g00ecf