All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ice: Fix memleak in ice_set_ringparam
@ 2020-08-27  2:34 ` Dinghao Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Dinghao Liu @ 2020-08-27  2:34 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Jeff Kirsher, David S. Miller, Jakub Kicinski,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, intel-wired-lan, netdev, linux-kernel, bpf

When kcalloc() on rx_rings fails, we should free tx_rings
and xdp_rings to prevent memleak. Similarly, when
ice_alloc_rx_bufs() fails, we should free xdp_rings.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index 9e8e9531cd87..caf64eb5e96d 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -2863,7 +2863,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 	rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
 	if (!rx_rings) {
 		err = -ENOMEM;
-		goto done;
+		goto free_xdp;
 	}
 
 	ice_for_each_rxq(vsi, i) {
@@ -2892,7 +2892,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 			}
 			kfree(rx_rings);
 			err = -ENOMEM;
-			goto free_tx;
+			goto free_xdp;
 		}
 	}
 
@@ -2943,6 +2943,15 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 	}
 	goto done;
 
+free_xdp:
+	if (xdp_rings) {
+		for (i = 0; i < vsi->num_xdp_txq; i++) {
+			ice_free_tx_ring(vsi->xdp_rings[i]);
+			*vsi->xdp_rings[i] = xdp_rings[i];
+		}
+		kfree(xdp_rings);
+	}
+
 free_tx:
 	/* error cleanup if the Rx allocations failed after getting Tx */
 	if (tx_rings) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Intel-wired-lan] [PATCH] ice: Fix memleak in ice_set_ringparam
@ 2020-08-27  2:34 ` Dinghao Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Dinghao Liu @ 2020-08-27  2:34 UTC (permalink / raw)
  To: intel-wired-lan

When kcalloc() on rx_rings fails, we should free tx_rings
and xdp_rings to prevent memleak. Similarly, when
ice_alloc_rx_bufs() fails, we should free xdp_rings.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index 9e8e9531cd87..caf64eb5e96d 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -2863,7 +2863,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 	rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
 	if (!rx_rings) {
 		err = -ENOMEM;
-		goto done;
+		goto free_xdp;
 	}
 
 	ice_for_each_rxq(vsi, i) {
@@ -2892,7 +2892,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 			}
 			kfree(rx_rings);
 			err = -ENOMEM;
-			goto free_tx;
+			goto free_xdp;
 		}
 	}
 
@@ -2943,6 +2943,15 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
 	}
 	goto done;
 
+free_xdp:
+	if (xdp_rings) {
+		for (i = 0; i < vsi->num_xdp_txq; i++) {
+			ice_free_tx_ring(vsi->xdp_rings[i]);
+			*vsi->xdp_rings[i] = xdp_rings[i];
+		}
+		kfree(xdp_rings);
+	}
+
 free_tx:
 	/* error cleanup if the Rx allocations failed after getting Tx */
 	if (tx_rings) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] ice: Fix memleak in ice_set_ringparam
  2020-08-27  2:34 ` [Intel-wired-lan] " Dinghao Liu
@ 2020-09-05  2:52   ` Brown, Aaron F
  -1 siblings, 0 replies; 4+ messages in thread
From: Brown, Aaron F @ 2020-09-05  2:52 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Kirsher, Jeffrey T, David S. Miller, Jakub Kicinski,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, intel-wired-lan, netdev, linux-kernel, bpf

> From: Dinghao Liu <dinghao.liu@zju.edu.cn>
> Sent: Wednesday, August 26, 2020 7:34 PM
> To: dinghao.liu@zju.edu.cn; kjlu@umn.edu
> Cc: Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>; David S. Miller
> <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Alexei
> Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>;
> Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend
> <john.fastabend@gmail.com>; intel-wired-lan@lists.osuosl.org;
> netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> bpf@vger.kernel.org
> Subject: [PATCH] ice: Fix memleak in ice_set_ringparam
> 
> When kcalloc() on rx_rings fails, we should free tx_rings
> and xdp_rings to prevent memleak. Similarly, when
> ice_alloc_rx_bufs() fails, we should free xdp_rings.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/net/ethernet/intel/ice/ice_ethtool.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Intel-wired-lan] [PATCH] ice: Fix memleak in ice_set_ringparam
@ 2020-09-05  2:52   ` Brown, Aaron F
  0 siblings, 0 replies; 4+ messages in thread
From: Brown, Aaron F @ 2020-09-05  2:52 UTC (permalink / raw)
  To: intel-wired-lan

> From: Dinghao Liu <dinghao.liu@zju.edu.cn>
> Sent: Wednesday, August 26, 2020 7:34 PM
> To: dinghao.liu at zju.edu.cn; kjlu at umn.edu
> Cc: Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>; David S. Miller
> <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Alexei
> Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>;
> Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend
> <john.fastabend@gmail.com>; intel-wired-lan at lists.osuosl.org;
> netdev at vger.kernel.org; linux-kernel at vger.kernel.org;
> bpf at vger.kernel.org
> Subject: [PATCH] ice: Fix memleak in ice_set_ringparam
> 
> When kcalloc() on rx_rings fails, we should free tx_rings
> and xdp_rings to prevent memleak. Similarly, when
> ice_alloc_rx_bufs() fails, we should free xdp_rings.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/net/ethernet/intel/ice/ice_ethtool.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-05  2:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27  2:34 [PATCH] ice: Fix memleak in ice_set_ringparam Dinghao Liu
2020-08-27  2:34 ` [Intel-wired-lan] " Dinghao Liu
2020-09-05  2:52 ` Brown, Aaron F
2020-09-05  2:52   ` [Intel-wired-lan] " Brown, Aaron F

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.