Commit b539ea60 authored by Arjun Vynipadath's avatar Arjun Vynipadath Committed by David S. Miller

cxgb4/cxgb4vf: Fix mac_hlist initialization and free

Null pointer dereference seen when cxgb4vf driver is unloaded
without bringing up any interfaces, moving mac_hlist initialization
to driver probe and free the mac_hlist in remove to fix the issue.

Fixes: 24357e06 ("cxgb4vf: fix memleak in mac_hlist initialization")
Signed-off-by: default avatarArjun Vynipadath <arjun@chelsio.com>
Signed-off-by: default avatarCasey Leedom <leedom@chelsio.com>
Signed-off-by: default avatarGanesh Goudar <ganeshgr@chelsio.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ade9628e
...@@ -2280,8 +2280,6 @@ static int cxgb_up(struct adapter *adap) ...@@ -2280,8 +2280,6 @@ static int cxgb_up(struct adapter *adap)
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
update_clip(adap); update_clip(adap);
#endif #endif
/* Initialize hash mac addr list*/
INIT_LIST_HEAD(&adap->mac_hlist);
return err; return err;
irq_err: irq_err:
...@@ -2295,8 +2293,6 @@ static int cxgb_up(struct adapter *adap) ...@@ -2295,8 +2293,6 @@ static int cxgb_up(struct adapter *adap)
static void cxgb_down(struct adapter *adapter) static void cxgb_down(struct adapter *adapter)
{ {
struct hash_mac_addr *entry, *tmp;
cancel_work_sync(&adapter->tid_release_task); cancel_work_sync(&adapter->tid_release_task);
cancel_work_sync(&adapter->db_full_task); cancel_work_sync(&adapter->db_full_task);
cancel_work_sync(&adapter->db_drop_task); cancel_work_sync(&adapter->db_drop_task);
...@@ -2306,11 +2302,6 @@ static void cxgb_down(struct adapter *adapter) ...@@ -2306,11 +2302,6 @@ static void cxgb_down(struct adapter *adapter)
t4_sge_stop(adapter); t4_sge_stop(adapter);
t4_free_sge_resources(adapter); t4_free_sge_resources(adapter);
list_for_each_entry_safe(entry, tmp, &adapter->mac_hlist, list) {
list_del(&entry->list);
kfree(entry);
}
adapter->flags &= ~FULL_INIT_DONE; adapter->flags &= ~FULL_INIT_DONE;
} }
...@@ -5629,6 +5620,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -5629,6 +5620,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
(is_t5(adapter->params.chip) ? STATMODE_V(0) : (is_t5(adapter->params.chip) ? STATMODE_V(0) :
T6_STATMODE_V(0))); T6_STATMODE_V(0)));
/* Initialize hash mac addr list */
INIT_LIST_HEAD(&adapter->mac_hlist);
for_each_port(adapter, i) { for_each_port(adapter, i) {
netdev = alloc_etherdev_mq(sizeof(struct port_info), netdev = alloc_etherdev_mq(sizeof(struct port_info),
MAX_ETH_QSETS); MAX_ETH_QSETS);
...@@ -5907,6 +5901,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -5907,6 +5901,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
static void remove_one(struct pci_dev *pdev) static void remove_one(struct pci_dev *pdev)
{ {
struct adapter *adapter = pci_get_drvdata(pdev); struct adapter *adapter = pci_get_drvdata(pdev);
struct hash_mac_addr *entry, *tmp;
if (!adapter) { if (!adapter) {
pci_release_regions(pdev); pci_release_regions(pdev);
...@@ -5956,6 +5951,12 @@ static void remove_one(struct pci_dev *pdev) ...@@ -5956,6 +5951,12 @@ static void remove_one(struct pci_dev *pdev)
if (adapter->num_uld || adapter->num_ofld_uld) if (adapter->num_uld || adapter->num_ofld_uld)
t4_uld_mem_free(adapter); t4_uld_mem_free(adapter);
free_some_resources(adapter); free_some_resources(adapter);
list_for_each_entry_safe(entry, tmp, &adapter->mac_hlist,
list) {
list_del(&entry->list);
kfree(entry);
}
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
t4_cleanup_clip_tbl(adapter); t4_cleanup_clip_tbl(adapter);
#endif #endif
......
...@@ -723,9 +723,6 @@ static int adapter_up(struct adapter *adapter) ...@@ -723,9 +723,6 @@ static int adapter_up(struct adapter *adapter)
if (adapter->flags & USING_MSIX) if (adapter->flags & USING_MSIX)
name_msix_vecs(adapter); name_msix_vecs(adapter);
/* Initialize hash mac addr list*/
INIT_LIST_HEAD(&adapter->mac_hlist);
adapter->flags |= FULL_INIT_DONE; adapter->flags |= FULL_INIT_DONE;
} }
...@@ -3038,6 +3035,9 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev, ...@@ -3038,6 +3035,9 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
if (err) if (err)
goto err_unmap_bar; goto err_unmap_bar;
/* Initialize hash mac addr list */
INIT_LIST_HEAD(&adapter->mac_hlist);
/* /*
* Allocate our "adapter ports" and stitch everything together. * Allocate our "adapter ports" and stitch everything together.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment