diff mbox series

ice: memory leak in ice_vsi_alloc_stat_arrays

Message ID 20230111103630.17629-1-michal.swiatkowski@linux.intel.com
State Accepted
Delegated to: Anthony Nguyen
Headers show
Series ice: memory leak in ice_vsi_alloc_stat_arrays | expand

Commit Message

Michal Swiatkowski Jan. 11, 2023, 10:36 a.m. UTC
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(-)

Comments

Dave Ertman Jan. 12, 2023, 5:02 p.m. UTC | #1
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Michal Swiatkowski
> Sent: Wednesday, January 11, 2023 2:37 AM
> To: intel-wired-lan@lists.osuosl.org
> Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; error27@gmail.com
> Subject: [Intel-wired-lan] [PATCH] ice: memory leak in
> ice_vsi_alloc_stat_arrays
> 
> 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(-)
> 

Thanks for catching this!

Reviewed-by: Dave Ertman <david.m.ertman@intel.com>
Dave Ertman Jan. 12, 2023, 5:38 p.m. UTC | #2
> -----Original Message-----
> From: Ertman, David M
> Sent: Thursday, January 12, 2023 9:03 AM
> To: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>; intel-wired-
> lan@lists.osuosl.org
> Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; error27@gmail.com
> Subject: RE: [Intel-wired-lan] [PATCH] ice: memory leak in
> ice_vsi_alloc_stat_arrays
> 
> > -----Original Message-----
> > From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> > Michal Swiatkowski
> > Sent: Wednesday, January 11, 2023 2:37 AM
> > To: intel-wired-lan@lists.osuosl.org
> > Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>;
> error27@gmail.com
> > Subject: [Intel-wired-lan] [PATCH] ice: memory leak in
> > ice_vsi_alloc_stat_arrays
> >
> > 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(-)
> >
> 
> Thanks for catching this!
> 
> Reviewed-by: Dave Ertman <david.m.ertman@intel.com>

Please clean-up variable ret, since it is not needed any more. Also can probably clean up braces that won't be
needed any more also.

DaveE
Michal Swiatkowski Jan. 13, 2023, 6:19 a.m. UTC | #3
On Thu, Jan 12, 2023 at 05:38:29PM +0000, Ertman, David M wrote:
> > -----Original Message-----
> > From: Ertman, David M
> > Sent: Thursday, January 12, 2023 9:03 AM
> > To: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>; intel-wired-
> > lan@lists.osuosl.org
> > Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; error27@gmail.com
> > Subject: RE: [Intel-wired-lan] [PATCH] ice: memory leak in
> > ice_vsi_alloc_stat_arrays
> > 
> > > -----Original Message-----
> > > From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> > > Michal Swiatkowski
> > > Sent: Wednesday, January 11, 2023 2:37 AM
> > > To: intel-wired-lan@lists.osuosl.org
> > > Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>;
> > error27@gmail.com
> > > Subject: [Intel-wired-lan] [PATCH] ice: memory leak in
> > > ice_vsi_alloc_stat_arrays
> > >
> > > 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(-)
> > >
> > 
> > Thanks for catching this!
> > 
> > Reviewed-by: Dave Ertman <david.m.ertman@intel.com>
> 
> Please clean-up variable ret, since it is not needed any more. Also can probably clean up braces that won't be
> needed any more also.
> 
Done, thanks

> DaveE
G, GurucharanX Jan. 24, 2023, 3:14 a.m. UTC | #4
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Michal Swiatkowski
> Sent: Wednesday, January 11, 2023 4:07 PM
> To: intel-wired-lan@lists.osuosl.org
> Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; error27@gmail.com
> Subject: [Intel-wired-lan] [PATCH] ice: memory leak in
> ice_vsi_alloc_stat_arrays
> 
> 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(-)
> 

Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
diff mbox series

Patch

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);