e1000: ensure to free old tx/rx rings in set_ringparam()

Message ID 20180723160130.8911-2-jeffrey.t.kirsher@intel.com
State Accepted
Delegated to: Jeff Kirsher
Headers show
Series
  • e1000: ensure to free old tx/rx rings in set_ringparam()
Related show

Commit Message

Jeff Kirsher July 23, 2018, 4:01 p.m.
From: Bo Chen <chenbo@pdx.edu>

In 'e1000_set_ringparam()', the tx_ring and rx_ring are updated with new value
and the old tx/rx rings are freed only when the device is up. There are resource
leaks on old tx/rx rings when the device is not up. This bug is reported by COD,
a tool for testing kernel module binaries I am building.

This patch fixes the bug by always calling 'kfree()' on old tx/rx rings in
'e1000_set_ringparam()'.

Signed-off-by: Bo Chen <chenbo@pdx.edu>
Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
 drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Brown, Aaron F Aug. 2, 2018, 10:04 p.m. | #1
> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Jeff Kirsher
> Sent: Monday, July 23, 2018 9:02 AM
> To: intel-wired-lan@lists.osuosl.org
> Cc: Bo Chen <chenbo@pdx.edu>
> Subject: [Intel-wired-lan] e1000: ensure to free old tx/rx rings in
> set_ringparam()
> 
> From: Bo Chen <chenbo@pdx.edu>
> 
> In 'e1000_set_ringparam()', the tx_ring and rx_ring are updated with new
> value
> and the old tx/rx rings are freed only when the device is up. There are
> resource
> leaks on old tx/rx rings when the device is not up. This bug is reported by
> COD,
> a tool for testing kernel module binaries I am building.
> 
> This patch fixes the bug by always calling 'kfree()' on old tx/rx rings in
> 'e1000_set_ringparam()'.
> 
> Signed-off-by: Bo Chen <chenbo@pdx.edu>
> Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
> ---
>  drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

Patch

diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
index bdb3f8e65ed4..27b006b60f8b 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
@@ -624,14 +624,14 @@  static int e1000_set_ringparam(struct net_device *netdev,
 		adapter->tx_ring = tx_old;
 		e1000_free_all_rx_resources(adapter);
 		e1000_free_all_tx_resources(adapter);
-		kfree(tx_old);
-		kfree(rx_old);
 		adapter->rx_ring = rxdr;
 		adapter->tx_ring = txdr;
 		err = e1000_up(adapter);
 		if (err)
 			goto err_setup;
 	}
+	kfree(tx_old);
+	kfree(rx_old);
 
 	clear_bit(__E1000_RESETTING, &adapter->flags);
 	return 0;