Skip to content

Commit

Permalink
igb: fix memory leak when setting ring size while interface is down
Browse files Browse the repository at this point in the history
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: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexander Duyck authored and David S. Miller committed Oct 26, 2009
1 parent d3da683 commit 6d9f4fc
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions drivers/net/igb/igb_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ static int igb_set_ringparam(struct net_device *netdev,
{
struct igb_adapter *adapter = netdev_priv(netdev);
struct igb_ring *temp_ring;
int i, err;
int i, err = 0;
u32 new_rx_count, new_tx_count;

if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
Expand All @@ -751,18 +751,30 @@ static int igb_set_ringparam(struct net_device *netdev,
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)
temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
else
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))
msleep(1);
if (!temp_ring) {
err = -ENOMEM;
goto clear_reset;
}

if (netif_running(adapter->netdev))
igb_down(adapter);
igb_down(adapter);

/*
* We can't just free everything and then setup again,
Expand Down Expand Up @@ -819,14 +831,11 @@ static int igb_set_ringparam(struct net_device *netdev,

adapter->rx_ring_count = new_rx_count;
}

err = 0;
err_setup:
if (netif_running(adapter->netdev))
igb_up(adapter);

clear_bit(__IGB_RESETTING, &adapter->state);
igb_up(adapter);
vfree(temp_ring);
clear_reset:
clear_bit(__IGB_RESETTING, &adapter->state);
return err;
}

Expand Down

0 comments on commit 6d9f4fc

Please sign in to comment.