Commit 361b1231 authored by David S. Miller's avatar David S. Miller

Merge branch 'ibmvnic-leaks'

Thomas Falcon says:

====================
ibmvnic: Fix memory leaks in the driver

This patch set is pretty self-explanatory. It includes
a number of patches that fix memory leaks found with
kmemleak in the ibmvnic driver.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents cc85c02e d0869c00
...@@ -791,6 +791,18 @@ static int ibmvnic_login(struct net_device *netdev) ...@@ -791,6 +791,18 @@ static int ibmvnic_login(struct net_device *netdev)
return 0; return 0;
} }
static void release_login_buffer(struct ibmvnic_adapter *adapter)
{
kfree(adapter->login_buf);
adapter->login_buf = NULL;
}
static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
{
kfree(adapter->login_rsp_buf);
adapter->login_rsp_buf = NULL;
}
static void release_resources(struct ibmvnic_adapter *adapter) static void release_resources(struct ibmvnic_adapter *adapter)
{ {
int i; int i;
...@@ -813,6 +825,10 @@ static void release_resources(struct ibmvnic_adapter *adapter) ...@@ -813,6 +825,10 @@ static void release_resources(struct ibmvnic_adapter *adapter)
} }
} }
} }
kfree(adapter->napi);
adapter->napi = NULL;
release_login_rsp_buffer(adapter);
} }
static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state) static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
...@@ -1057,6 +1073,35 @@ static int ibmvnic_open(struct net_device *netdev) ...@@ -1057,6 +1073,35 @@ static int ibmvnic_open(struct net_device *netdev)
return rc; return rc;
} }
static void clean_rx_pools(struct ibmvnic_adapter *adapter)
{
struct ibmvnic_rx_pool *rx_pool;
u64 rx_entries;
int rx_scrqs;
int i, j;
if (!adapter->rx_pool)
return;
rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
rx_entries = adapter->req_rx_add_entries_per_subcrq;
/* Free any remaining skbs in the rx buffer pools */
for (i = 0; i < rx_scrqs; i++) {
rx_pool = &adapter->rx_pool[i];
if (!rx_pool)
continue;
netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i);
for (j = 0; j < rx_entries; j++) {
if (rx_pool->rx_buff[j].skb) {
dev_kfree_skb_any(rx_pool->rx_buff[j].skb);
rx_pool->rx_buff[j].skb = NULL;
}
}
}
}
static void clean_tx_pools(struct ibmvnic_adapter *adapter) static void clean_tx_pools(struct ibmvnic_adapter *adapter)
{ {
struct ibmvnic_tx_pool *tx_pool; struct ibmvnic_tx_pool *tx_pool;
...@@ -1134,7 +1179,7 @@ static int __ibmvnic_close(struct net_device *netdev) ...@@ -1134,7 +1179,7 @@ static int __ibmvnic_close(struct net_device *netdev)
} }
} }
} }
clean_rx_pools(adapter);
clean_tx_pools(adapter); clean_tx_pools(adapter);
adapter->state = VNIC_CLOSED; adapter->state = VNIC_CLOSED;
return rc; return rc;
...@@ -1853,6 +1898,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget) ...@@ -1853,6 +1898,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
be16_to_cpu(next->rx_comp.rc)); be16_to_cpu(next->rx_comp.rc));
/* free the entry */ /* free the entry */
next->rx_comp.first = 0; next->rx_comp.first = 0;
dev_kfree_skb_any(rx_buff->skb);
remove_buff_from_pool(adapter, rx_buff); remove_buff_from_pool(adapter, rx_buff);
continue; continue;
} }
...@@ -3013,6 +3059,7 @@ static void send_login(struct ibmvnic_adapter *adapter) ...@@ -3013,6 +3059,7 @@ static void send_login(struct ibmvnic_adapter *adapter)
struct vnic_login_client_data *vlcd; struct vnic_login_client_data *vlcd;
int i; int i;
release_login_rsp_buffer(adapter);
client_data_len = vnic_client_data_len(adapter); client_data_len = vnic_client_data_len(adapter);
buffer_size = buffer_size =
...@@ -3708,6 +3755,7 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, ...@@ -3708,6 +3755,7 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
DMA_BIDIRECTIONAL); DMA_BIDIRECTIONAL);
release_login_buffer(adapter);
dma_unmap_single(dev, adapter->login_rsp_buf_token, dma_unmap_single(dev, adapter->login_rsp_buf_token,
adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL); adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
......
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