All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: mm/damon/dbgfs.c:396 dbgfs_mk_context_write() warn: passing a valid pointer to 'PTR_ERR'
Date: Sun, 05 Dec 2021 10:33:56 +0800	[thread overview]
Message-ID: <202112051012.gkhSfyxT-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 9605 bytes --]

CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   79a72162048e42a677bc7336a9f5d86fc3ff9558
commit: 75c1c2b53c78bf3b3188ebb7b3508dadbf98bba1 mm/damon/dbgfs: support multiple contexts
date:   3 months ago
:::::: branch date: 65 minutes ago
:::::: commit date: 3 months ago
config: nios2-randconfig-m031-20211202 (https://download.01.org/0day-ci/archive/20211205/202112051012.gkhSfyxT-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.2.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/damon/dbgfs.c:396 dbgfs_mk_context_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:487 dbgfs_rm_context_write() warn: passing a valid pointer to 'PTR_ERR'

vim +/PTR_ERR +396 mm/damon/dbgfs.c

75c1c2b53c78bf SeongJae Park 2021-09-07  385  
75c1c2b53c78bf SeongJae Park 2021-09-07  386  static ssize_t dbgfs_mk_context_write(struct file *file,
75c1c2b53c78bf SeongJae Park 2021-09-07  387  		const char __user *buf, size_t count, loff_t *ppos)
75c1c2b53c78bf SeongJae Park 2021-09-07  388  {
75c1c2b53c78bf SeongJae Park 2021-09-07  389  	char *kbuf;
75c1c2b53c78bf SeongJae Park 2021-09-07  390  	char *ctx_name;
75c1c2b53c78bf SeongJae Park 2021-09-07  391  	ssize_t ret = count;
75c1c2b53c78bf SeongJae Park 2021-09-07  392  	int err;
75c1c2b53c78bf SeongJae Park 2021-09-07  393  
75c1c2b53c78bf SeongJae Park 2021-09-07  394  	kbuf = user_input_str(buf, count, ppos);
75c1c2b53c78bf SeongJae Park 2021-09-07  395  	if (IS_ERR(kbuf))
75c1c2b53c78bf SeongJae Park 2021-09-07 @396  		return PTR_ERR(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  397  	ctx_name = kmalloc(count + 1, GFP_KERNEL);
75c1c2b53c78bf SeongJae Park 2021-09-07  398  	if (!ctx_name) {
75c1c2b53c78bf SeongJae Park 2021-09-07  399  		kfree(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  400  		return -ENOMEM;
75c1c2b53c78bf SeongJae Park 2021-09-07  401  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  402  
75c1c2b53c78bf SeongJae Park 2021-09-07  403  	/* Trim white space */
75c1c2b53c78bf SeongJae Park 2021-09-07  404  	if (sscanf(kbuf, "%s", ctx_name) != 1) {
75c1c2b53c78bf SeongJae Park 2021-09-07  405  		ret = -EINVAL;
75c1c2b53c78bf SeongJae Park 2021-09-07  406  		goto out;
75c1c2b53c78bf SeongJae Park 2021-09-07  407  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  408  
75c1c2b53c78bf SeongJae Park 2021-09-07  409  	mutex_lock(&damon_dbgfs_lock);
75c1c2b53c78bf SeongJae Park 2021-09-07  410  	err = dbgfs_mk_context(ctx_name);
75c1c2b53c78bf SeongJae Park 2021-09-07  411  	if (err)
75c1c2b53c78bf SeongJae Park 2021-09-07  412  		ret = err;
75c1c2b53c78bf SeongJae Park 2021-09-07  413  	mutex_unlock(&damon_dbgfs_lock);
75c1c2b53c78bf SeongJae Park 2021-09-07  414  
75c1c2b53c78bf SeongJae Park 2021-09-07  415  out:
75c1c2b53c78bf SeongJae Park 2021-09-07  416  	kfree(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  417  	kfree(ctx_name);
75c1c2b53c78bf SeongJae Park 2021-09-07  418  	return ret;
75c1c2b53c78bf SeongJae Park 2021-09-07  419  }
75c1c2b53c78bf SeongJae Park 2021-09-07  420  
75c1c2b53c78bf SeongJae Park 2021-09-07  421  /*
75c1c2b53c78bf SeongJae Park 2021-09-07  422   * Remove a context of @name and its debugfs directory.
75c1c2b53c78bf SeongJae Park 2021-09-07  423   *
75c1c2b53c78bf SeongJae Park 2021-09-07  424   * This function should be called while holding damon_dbgfs_lock.
75c1c2b53c78bf SeongJae Park 2021-09-07  425   *
75c1c2b53c78bf SeongJae Park 2021-09-07  426   * Return 0 on success, negative error code otherwise.
75c1c2b53c78bf SeongJae Park 2021-09-07  427   */
75c1c2b53c78bf SeongJae Park 2021-09-07  428  static int dbgfs_rm_context(char *name)
75c1c2b53c78bf SeongJae Park 2021-09-07  429  {
75c1c2b53c78bf SeongJae Park 2021-09-07  430  	struct dentry *root, *dir, **new_dirs;
75c1c2b53c78bf SeongJae Park 2021-09-07  431  	struct damon_ctx **new_ctxs;
75c1c2b53c78bf SeongJae Park 2021-09-07  432  	int i, j;
75c1c2b53c78bf SeongJae Park 2021-09-07  433  
75c1c2b53c78bf SeongJae Park 2021-09-07  434  	if (damon_nr_running_ctxs())
75c1c2b53c78bf SeongJae Park 2021-09-07  435  		return -EBUSY;
75c1c2b53c78bf SeongJae Park 2021-09-07  436  
75c1c2b53c78bf SeongJae Park 2021-09-07  437  	root = dbgfs_dirs[0];
75c1c2b53c78bf SeongJae Park 2021-09-07  438  	if (!root)
75c1c2b53c78bf SeongJae Park 2021-09-07  439  		return -ENOENT;
75c1c2b53c78bf SeongJae Park 2021-09-07  440  
75c1c2b53c78bf SeongJae Park 2021-09-07  441  	dir = debugfs_lookup(name, root);
75c1c2b53c78bf SeongJae Park 2021-09-07  442  	if (!dir)
75c1c2b53c78bf SeongJae Park 2021-09-07  443  		return -ENOENT;
75c1c2b53c78bf SeongJae Park 2021-09-07  444  
75c1c2b53c78bf SeongJae Park 2021-09-07  445  	new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs),
75c1c2b53c78bf SeongJae Park 2021-09-07  446  			GFP_KERNEL);
75c1c2b53c78bf SeongJae Park 2021-09-07  447  	if (!new_dirs)
75c1c2b53c78bf SeongJae Park 2021-09-07  448  		return -ENOMEM;
75c1c2b53c78bf SeongJae Park 2021-09-07  449  
75c1c2b53c78bf SeongJae Park 2021-09-07  450  	new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs),
75c1c2b53c78bf SeongJae Park 2021-09-07  451  			GFP_KERNEL);
75c1c2b53c78bf SeongJae Park 2021-09-07  452  	if (!new_ctxs) {
75c1c2b53c78bf SeongJae Park 2021-09-07  453  		kfree(new_dirs);
75c1c2b53c78bf SeongJae Park 2021-09-07  454  		return -ENOMEM;
75c1c2b53c78bf SeongJae Park 2021-09-07  455  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  456  
75c1c2b53c78bf SeongJae Park 2021-09-07  457  	for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) {
75c1c2b53c78bf SeongJae Park 2021-09-07  458  		if (dbgfs_dirs[i] == dir) {
75c1c2b53c78bf SeongJae Park 2021-09-07  459  			debugfs_remove(dbgfs_dirs[i]);
75c1c2b53c78bf SeongJae Park 2021-09-07  460  			dbgfs_destroy_ctx(dbgfs_ctxs[i]);
75c1c2b53c78bf SeongJae Park 2021-09-07  461  			continue;
75c1c2b53c78bf SeongJae Park 2021-09-07  462  		}
75c1c2b53c78bf SeongJae Park 2021-09-07  463  		new_dirs[j] = dbgfs_dirs[i];
75c1c2b53c78bf SeongJae Park 2021-09-07  464  		new_ctxs[j++] = dbgfs_ctxs[i];
75c1c2b53c78bf SeongJae Park 2021-09-07  465  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  466  
75c1c2b53c78bf SeongJae Park 2021-09-07  467  	kfree(dbgfs_dirs);
75c1c2b53c78bf SeongJae Park 2021-09-07  468  	kfree(dbgfs_ctxs);
75c1c2b53c78bf SeongJae Park 2021-09-07  469  
75c1c2b53c78bf SeongJae Park 2021-09-07  470  	dbgfs_dirs = new_dirs;
75c1c2b53c78bf SeongJae Park 2021-09-07  471  	dbgfs_ctxs = new_ctxs;
75c1c2b53c78bf SeongJae Park 2021-09-07  472  	dbgfs_nr_ctxs--;
75c1c2b53c78bf SeongJae Park 2021-09-07  473  
75c1c2b53c78bf SeongJae Park 2021-09-07  474  	return 0;
75c1c2b53c78bf SeongJae Park 2021-09-07  475  }
75c1c2b53c78bf SeongJae Park 2021-09-07  476  
75c1c2b53c78bf SeongJae Park 2021-09-07  477  static ssize_t dbgfs_rm_context_write(struct file *file,
75c1c2b53c78bf SeongJae Park 2021-09-07  478  		const char __user *buf, size_t count, loff_t *ppos)
75c1c2b53c78bf SeongJae Park 2021-09-07  479  {
75c1c2b53c78bf SeongJae Park 2021-09-07  480  	char *kbuf;
75c1c2b53c78bf SeongJae Park 2021-09-07  481  	ssize_t ret = count;
75c1c2b53c78bf SeongJae Park 2021-09-07  482  	int err;
75c1c2b53c78bf SeongJae Park 2021-09-07  483  	char *ctx_name;
75c1c2b53c78bf SeongJae Park 2021-09-07  484  
75c1c2b53c78bf SeongJae Park 2021-09-07  485  	kbuf = user_input_str(buf, count, ppos);
75c1c2b53c78bf SeongJae Park 2021-09-07  486  	if (IS_ERR(kbuf))
75c1c2b53c78bf SeongJae Park 2021-09-07 @487  		return PTR_ERR(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  488  	ctx_name = kmalloc(count + 1, GFP_KERNEL);
75c1c2b53c78bf SeongJae Park 2021-09-07  489  	if (!ctx_name) {
75c1c2b53c78bf SeongJae Park 2021-09-07  490  		kfree(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  491  		return -ENOMEM;
75c1c2b53c78bf SeongJae Park 2021-09-07  492  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  493  
75c1c2b53c78bf SeongJae Park 2021-09-07  494  	/* Trim white space */
75c1c2b53c78bf SeongJae Park 2021-09-07  495  	if (sscanf(kbuf, "%s", ctx_name) != 1) {
75c1c2b53c78bf SeongJae Park 2021-09-07  496  		ret = -EINVAL;
75c1c2b53c78bf SeongJae Park 2021-09-07  497  		goto out;
75c1c2b53c78bf SeongJae Park 2021-09-07  498  	}
75c1c2b53c78bf SeongJae Park 2021-09-07  499  
75c1c2b53c78bf SeongJae Park 2021-09-07  500  	mutex_lock(&damon_dbgfs_lock);
75c1c2b53c78bf SeongJae Park 2021-09-07  501  	err = dbgfs_rm_context(ctx_name);
75c1c2b53c78bf SeongJae Park 2021-09-07  502  	if (err)
75c1c2b53c78bf SeongJae Park 2021-09-07  503  		ret = err;
75c1c2b53c78bf SeongJae Park 2021-09-07  504  	mutex_unlock(&damon_dbgfs_lock);
75c1c2b53c78bf SeongJae Park 2021-09-07  505  
75c1c2b53c78bf SeongJae Park 2021-09-07  506  out:
75c1c2b53c78bf SeongJae Park 2021-09-07  507  	kfree(kbuf);
75c1c2b53c78bf SeongJae Park 2021-09-07  508  	kfree(ctx_name);
75c1c2b53c78bf SeongJae Park 2021-09-07  509  	return ret;
75c1c2b53c78bf SeongJae Park 2021-09-07  510  }
75c1c2b53c78bf SeongJae Park 2021-09-07  511  

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

             reply	other threads:[~2021-12-05  2:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-05  2:33 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-08-21  7:02 mm/damon/dbgfs.c:396 dbgfs_mk_context_write() warn: passing a valid pointer to 'PTR_ERR' kernel test robot
2022-03-10 18:57 kernel test robot
2021-11-24 10:57 kernel test robot
2021-09-10 13:00 kernel test robot

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=202112051012.gkhSfyxT-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild@lists.01.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 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.