Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH] ice: memory leak in ice_vsi_alloc_stat_arrays
@ 2023-01-11 10:36 Michal Swiatkowski
  2023-01-12 17:02 ` Ertman, David M
  2023-01-24  3:14 ` G, GurucharanX
  0 siblings, 2 replies; 5+ messages in thread
From: Michal Swiatkowski @ 2023-01-11 10:36 UTC (permalink / raw)
  To: intel-wired-lan; +Cc: anthony.l.nguyen, error27

Fix memory leak by checking if stats were already allocated before
allocating new one.

Previously it was completely broken, because new allocated value was
checked instead of previous one.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
---
Should be squashed with commit eace2cbe7f5f
("ice: split ice_vsi_setup into smaller functions")
---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index a09cb4ac39e4..04f31a83e327 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -558,14 +558,14 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi)
 	if (!pf->vsi_stats)
 		return -ENOENT;
 
+	if (pf->vsi_stats[vsi->idx])
+	/* realloc will happen in rebuild path */
+		return 0;
+
 	vsi_stat = kzalloc(sizeof(*vsi_stat), GFP_KERNEL);
 	if (!vsi_stat)
 		return -ENOMEM;
 
-	if (vsi_stat->tx_ring_stats && vsi_stat->rx_ring_stats)
-	/* realloc will happen in rebuild path */
-		return 0;
-
 	vsi_stat->tx_ring_stats =
 		kcalloc(vsi->alloc_txq, sizeof(*vsi_stat->tx_ring_stats),
 			GFP_KERNEL);
-- 
2.36.1

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

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

end of thread, other threads:[~2023-01-24  3:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-11 10:36 [Intel-wired-lan] [PATCH] ice: memory leak in ice_vsi_alloc_stat_arrays Michal Swiatkowski
2023-01-12 17:02 ` Ertman, David M
2023-01-12 17:38   ` Ertman, David M
2023-01-13  6:19     ` Michal Swiatkowski
2023-01-24  3:14 ` G, GurucharanX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox