Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: oe-kbuild@lists.linux.dev,
	Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Intel Wired LAN <intel-wired-lan@lists.osuosl.org>,
	oe-kbuild-all@lists.linux.dev
Subject: [Intel-wired-lan] [tnguy-next-queue:dev-queue 50/62] drivers/net/ethernet/intel/ice/ice_lib.c:571 ice_vsi_alloc_stat_arrays() warn: possible memory leak of 'vsi_stat'
Date: Wed, 11 Jan 2023 07:22:37 +0300	[thread overview]
Message-ID: <202301110916.nD8vny59-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue.git dev-queue
head:   c9ebfbece30b59350bc6879be8ed954cecc6be05
commit: f833ce48581cfdf4b086d7c79cef79191b0a21d2 [50/62] ice: split ice_vsi_setup into smaller functions
config: x86_64-randconfig-m001-20230109
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>

New smatch warnings:
drivers/net/ethernet/intel/ice/ice_lib.c:571 ice_vsi_alloc_stat_arrays() warn: possible memory leak of 'vsi_stat'
drivers/net/ethernet/intel/ice/ice_lib.c:2846 ice_vsi_cfg_def() warn: missing error code 'ret'

Old smatch warnings:
drivers/net/ethernet/intel/ice/ice_lib.c:437 ice_vsi_alloc_ring_stats() warn: inconsistent indenting
drivers/net/ethernet/intel/ice/ice_lib.c:3527 ice_vsi_rebuild() warn: missing error code 'ret'

vim +/vsi_stat +571 drivers/net/ethernet/intel/ice/ice_lib.c

288ecf491b1654 Benjamin Mikailenko 2022-11-18  555  static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  556  {
288ecf491b1654 Benjamin Mikailenko 2022-11-18  557  	struct ice_vsi_stats *vsi_stat;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  558  	struct ice_pf *pf = vsi->back;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  559  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  560  	if (vsi->type == ICE_VSI_CHNL)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  561  		return 0;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  562  	if (!pf->vsi_stats)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  563  		return -ENOENT;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  564  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  565  	vsi_stat = kzalloc(sizeof(*vsi_stat), GFP_KERNEL);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  566  	if (!vsi_stat)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  567  		return -ENOMEM;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  568  
f833ce48581cfd Michal Swiatkowski  2022-12-21  569  	if (vsi_stat->tx_ring_stats && vsi_stat->rx_ring_stats)
f833ce48581cfd Michal Swiatkowski  2022-12-21  570  	/* realloc will happen in rebuild path */
f833ce48581cfd Michal Swiatkowski  2022-12-21 @571  		return 0;


These aren't allocated until the next line so the return is impossible.
Just delete.  But Smatch is correct that it doesn't have a kfree() on
this path...

f833ce48581cfd Michal Swiatkowski  2022-12-21  572  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  573  	vsi_stat->tx_ring_stats =
288ecf491b1654 Benjamin Mikailenko 2022-11-18  574  		kcalloc(vsi->alloc_txq, sizeof(*vsi_stat->tx_ring_stats),
288ecf491b1654 Benjamin Mikailenko 2022-11-18  575  			GFP_KERNEL);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  576  	if (!vsi_stat->tx_ring_stats)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  577  		goto err_alloc_tx;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  578  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  579  	vsi_stat->rx_ring_stats =
288ecf491b1654 Benjamin Mikailenko 2022-11-18  580  		kcalloc(vsi->alloc_rxq, sizeof(*vsi_stat->rx_ring_stats),
288ecf491b1654 Benjamin Mikailenko 2022-11-18  581  			GFP_KERNEL);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  582  	if (!vsi_stat->rx_ring_stats)
288ecf491b1654 Benjamin Mikailenko 2022-11-18  583  		goto err_alloc_rx;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  584  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  585  	pf->vsi_stats[vsi->idx] = vsi_stat;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  586  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  587  	return 0;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  588  
288ecf491b1654 Benjamin Mikailenko 2022-11-18  589  err_alloc_rx:
288ecf491b1654 Benjamin Mikailenko 2022-11-18  590  	kfree(vsi_stat->rx_ring_stats);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  591  err_alloc_tx:
288ecf491b1654 Benjamin Mikailenko 2022-11-18  592  	kfree(vsi_stat->tx_ring_stats);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  593  	kfree(vsi_stat);
288ecf491b1654 Benjamin Mikailenko 2022-11-18  594  	pf->vsi_stats[vsi->idx] = NULL;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  595  	return -ENOMEM;
288ecf491b1654 Benjamin Mikailenko 2022-11-18  596  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

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

                 reply	other threads:[~2023-01-11 16:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202301110916.nD8vny59-lkp@intel.com \
    --to=error27@gmail.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=michal.swiatkowski@linux.intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox