linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Faiyaz Mohammed <faiyazm@codeaurora.org>,
	cl@linux.com, penberg@kernel.org, rientjes@google.com,
	iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
	vbabka@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	glittao@gmail.com
Cc: lkp@intel.com, kbuild-all@lists.01.org, vinmenon@codeaurora.org
Subject: Re: [PATCH v5] mm: slub: move sysfs slab alloc/free interfaces to debugfs
Date: Fri, 7 May 2021 08:21:20 +0300	[thread overview]
Message-ID: <202105070253.GuJL1RPR-lkp@intel.com> (raw)
In-Reply-To: <1620296523-21922-1-git-send-email-faiyazm@codeaurora.org>

Hi Faiyaz,

url:    https://github.com/0day-ci/linux/commits/Faiyaz-Mohammed/mm-slub-move-sysfs-slab-alloc-free-interfaces-to-debugfs/20210506-182420
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8404c9fbc84b741f66cff7d4934a25dd2c344452
config: i386-randconfig-m021-20210506 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
mm/slub.c:5891 slab_debugfs_start() warn: possible memory leak of 'spos'

vim +/spos +5891 mm/slub.c

88e180b99466c1 Faiyaz Mohammed 2021-05-06  5877  static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5878  {
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5879  	struct kmem_cache_node *n;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5880  	struct kmem_cache *s;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5881  	enum track_item alloc;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5882  	int node;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5883  	loff_t *spos = kmalloc(sizeof(loff_t), GFP_KERNEL);
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Generally avoid putting functions which can fail in the declaration
block.  Allocations inside the declaration block are a tiny percent of
declarations over all but they are an outsize source of static checker
bugs.

88e180b99466c1 Faiyaz Mohammed 2021-05-06  5884  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5885  	s = seq->file->f_inode->i_private;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5886  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5887  	if (!spos)
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5888  		return NULL;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5889  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5890  	if (!(s->flags & SLAB_STORE_USER))
88e180b99466c1 Faiyaz Mohammed 2021-05-06 @5891  		return ERR_PTR(-EOPNOTSUPP);

"spos" is leaked.

88e180b99466c1 Faiyaz Mohammed 2021-05-06  5892  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5893  	if (*ppos == 0) {
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5894  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5895  		t.count = 0;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5896  		t.max = 0;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5897  		t.loc = NULL;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5898  		if (strcmp(seq->file->f_path.dentry->d_name.name, "alloc_traces") == 0)
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5899  			alloc =  TRACK_ALLOC;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5900  		else
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5901  			alloc =  TRACK_FREE;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5902  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5903  		if (!alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location),
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5904  			     GFP_KERNEL)) {
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5905  			seq_puts(seq, "Out of memory\n");
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5906  			return ERR_PTR(-ENOMEM);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5907  		}
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5908  		/* Push back cpu slabs */
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5909  		flush_all(s);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5910  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5911  		for_each_kmem_cache_node(s, node, n) {
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5912  			unsigned long flags;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5913  			struct page *page;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5914  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5915  			if (!atomic_long_read(&n->nr_slabs))
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5916  				continue;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5917  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5918  			spin_lock_irqsave(&n->list_lock, flags);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5919  			list_for_each_entry(page, &n->partial, slab_list)
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5920  				process_slab(&t, s, page, alloc);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5921  			list_for_each_entry(page, &n->full, slab_list)
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5922  				process_slab(&t, s, page, alloc);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5923  			spin_unlock_irqrestore(&n->list_lock, flags);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5924  		}
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5925  	}
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5926  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5927  	if (*ppos < t.count) {
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5928  		*spos = *ppos;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5929  		return spos;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5930  	}
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5931  
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5932  	kfree(spos);
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5933  	return NULL;
88e180b99466c1 Faiyaz Mohammed 2021-05-06  5934  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org



  parent reply	other threads:[~2021-05-07  5:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 10:22 [PATCH v5] mm: slub: move sysfs slab alloc/free interfaces to debugfs Faiyaz Mohammed
2021-05-06 14:29 ` kernel test robot
2021-05-06 14:32 ` kernel test robot
2021-05-07  5:21 ` Dan Carpenter [this message]
2021-05-18 12:49   ` Faiyaz Mohammed
2021-05-07 11:48 ` Greg KH
2021-05-18 12:54   ` Faiyaz Mohammed
2021-05-18 13:33     ` Greg KH

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=202105070253.GuJL1RPR-lkp@intel.com \
    --to=dan.carpenter@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=faiyazm@codeaurora.org \
    --cc=glittao@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=vbabka@suse.cz \
    --cc=vinmenon@codeaurora.org \
    /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;
as well as URLs for NNTP newsgroup(s).