lkml.org 
[lkml]   [2022]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
Subjectlib/kunit/executor.c:80:10: warning: Potential leak of memory pointed to by 'copy' [clang-analyzer-unix.Malloc]
From
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 5a29232d870d9e63fe5ff30b081be6ea7cc2465d
commit: a02353f491622e49c7ddedc6a6dc4f1d6ed2150a kunit: bail out of test filtering logic quicker if OOM
date: 9 weeks ago
config: riscv-randconfig-c006-20220707 (https://download.01.org/0day-ci/archive/20220712/202207120840.9F6TBqZD-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 77a38f6839980bfac61babb40d83772c51427011)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a02353f491622e49c7ddedc6a6dc4f1d6ed2150a
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout a02353f491622e49c7ddedc6a6dc4f1d6ed2150a
# save the config file
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv clang-analyzer

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <yujie.liu@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)

>> lib/kunit/executor.c:80:10: warning: Potential leak of memory pointed to by 'copy' [clang-analyzer-unix.Malloc]
return ERR_PTR(-ENOMEM);
^

vim +/copy +80 lib/kunit/executor.c

a127b154a8f231 Daniel Latypov 2021-09-14 55
a127b154a8f231 Daniel Latypov 2021-09-14 56 /* Create a copy of suite with only tests that match test_glob. */
a127b154a8f231 Daniel Latypov 2021-09-14 57 static struct kunit_suite *
a127b154a8f231 Daniel Latypov 2021-09-14 58 kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
a127b154a8f231 Daniel Latypov 2021-09-14 59 {
a127b154a8f231 Daniel Latypov 2021-09-14 60 int n = 0;
a127b154a8f231 Daniel Latypov 2021-09-14 61 struct kunit_case *filtered, *test_case;
a127b154a8f231 Daniel Latypov 2021-09-14 62 struct kunit_suite *copy;
a127b154a8f231 Daniel Latypov 2021-09-14 63
a127b154a8f231 Daniel Latypov 2021-09-14 64 kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f231 Daniel Latypov 2021-09-14 65 if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f231 Daniel Latypov 2021-09-14 66 ++n;
a127b154a8f231 Daniel Latypov 2021-09-14 67 }
a127b154a8f231 Daniel Latypov 2021-09-14 68
a127b154a8f231 Daniel Latypov 2021-09-14 69 if (n == 0)
a127b154a8f231 Daniel Latypov 2021-09-14 70 return NULL;
a127b154a8f231 Daniel Latypov 2021-09-14 71
a127b154a8f231 Daniel Latypov 2021-09-14 72 /* Use memcpy to workaround copy->name being const. */
a127b154a8f231 Daniel Latypov 2021-09-14 73 copy = kmalloc(sizeof(*copy), GFP_KERNEL);
a02353f491622e Daniel Latypov 2022-05-11 74 if (!copy)
a02353f491622e Daniel Latypov 2022-05-11 75 return ERR_PTR(-ENOMEM);
a127b154a8f231 Daniel Latypov 2021-09-14 76 memcpy(copy, suite, sizeof(*copy));
a127b154a8f231 Daniel Latypov 2021-09-14 77
a127b154a8f231 Daniel Latypov 2021-09-14 78 filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
a02353f491622e Daniel Latypov 2022-05-11 79 if (!filtered)
a02353f491622e Daniel Latypov 2022-05-11 @80 return ERR_PTR(-ENOMEM);
a127b154a8f231 Daniel Latypov 2021-09-14 81
a127b154a8f231 Daniel Latypov 2021-09-14 82 n = 0;
a127b154a8f231 Daniel Latypov 2021-09-14 83 kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f231 Daniel Latypov 2021-09-14 84 if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f231 Daniel Latypov 2021-09-14 85 filtered[n++] = *test_case;
a127b154a8f231 Daniel Latypov 2021-09-14 86 }
a127b154a8f231 Daniel Latypov 2021-09-14 87
a127b154a8f231 Daniel Latypov 2021-09-14 88 copy->test_cases = filtered;
a127b154a8f231 Daniel Latypov 2021-09-14 89 return copy;
a127b154a8f231 Daniel Latypov 2021-09-14 90 }
5d31f71efcb6bc Daniel Latypov 2021-02-05 91

--
0-DAY CI Kernel Test Service
https://01.org/lkp

\
 
 \ /
  Last update: 2022-07-12 05:11    [W:3.163 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site