From: kernel test robot <yujie.liu@intel.com>
To: Daniel Latypov <dlatypov@google.com>
Cc: <llvm@lists.linux.dev>, <kbuild-all@lists.01.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Brendan Higgins <brendanhiggins@google.com>
Subject: lib/kunit/executor.c:80:10: warning: Potential leak of memory pointed to by 'copy' [clang-analyzer-unix.Malloc]
Date: Tue, 12 Jul 2022 11:10:20 +0800 [thread overview]
Message-ID: <c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com> (raw)
In-Reply-To: <202207120840.9F6TBqZD-lkp@intel.com>
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
parent reply other threads:[~2022-07-12 3:10 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <202207120840.9F6TBqZD-lkp@intel.com>]
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=c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com \
--to=yujie.liu@intel.com \
--cc=brendanhiggins@google.com \
--cc=dlatypov@google.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=skhan@linuxfoundation.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
all inboxes | Powered by JetHome®