Commit 6d9f4fc4 authored by Alexander Duyck's avatar Alexander Duyck Committed by David S. Miller

igb: fix memory leak when setting ring size while interface is down

Changing ring sizes while the interface was down was causing a double
allocation of the receive and transmit rings.  This issue is amplified when
there are multiple rings enabled.  To prevent this we need to add an
additional check which will just update the ring counts when the interface
is not up and skip the allocation steps.
Signed-off-by: default avatarAlexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d3da6831
...@@ -731,7 +731,7 @@ static int igb_set_ringparam(struct net_device *netdev, ...@@ -731,7 +731,7 @@ static int igb_set_ringparam(struct net_device *netdev,
{ {
struct igb_adapter *adapter = netdev_priv(netdev); struct igb_adapter *adapter = netdev_priv(netdev);
struct igb_ring *temp_ring; struct igb_ring *temp_ring;
int i, err; int i, err = 0;
u32 new_rx_count, new_tx_count; u32 new_rx_count, new_tx_count;
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
...@@ -751,17 +751,29 @@ static int igb_set_ringparam(struct net_device *netdev, ...@@ -751,17 +751,29 @@ static int igb_set_ringparam(struct net_device *netdev,
return 0; return 0;
} }
while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
msleep(1);
if (!netif_running(adapter->netdev)) {
for (i = 0; i < adapter->num_tx_queues; i++)
adapter->tx_ring[i].count = new_tx_count;
for (i = 0; i < adapter->num_rx_queues; i++)
adapter->rx_ring[i].count = new_rx_count;
adapter->tx_ring_count = new_tx_count;
adapter->rx_ring_count = new_rx_count;
goto clear_reset;
}
if (adapter->num_tx_queues > adapter->num_rx_queues) if (adapter->num_tx_queues > adapter->num_rx_queues)
temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring)); temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
else else
temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring)); temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
if (!temp_ring)
return -ENOMEM;
while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) if (!temp_ring) {
msleep(1); err = -ENOMEM;
goto clear_reset;
}
if (netif_running(adapter->netdev))
igb_down(adapter); igb_down(adapter);
/* /*
...@@ -819,14 +831,11 @@ static int igb_set_ringparam(struct net_device *netdev, ...@@ -819,14 +831,11 @@ static int igb_set_ringparam(struct net_device *netdev,
adapter->rx_ring_count = new_rx_count; adapter->rx_ring_count = new_rx_count;
} }
err = 0;
err_setup: err_setup:
if (netif_running(adapter->netdev))
igb_up(adapter); igb_up(adapter);
clear_bit(__IGB_RESETTING, &adapter->state);
vfree(temp_ring); vfree(temp_ring);
clear_reset:
clear_bit(__IGB_RESETTING, &adapter->state);
return err; return err;
} }
......
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