All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Daniel Latypov <dlatypov@google.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>,
	linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>,
	David Gow <davidgow@google.com>,
	Brendan Higgins <brendanhiggins@google.com>
Subject: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
Date: Tue, 12 Jul 2022 15:50:49 +0300	[thread overview]
Message-ID: <202207101328.ASjx88yj-lkp@intel.com> (raw)

tree:   https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit
head:   7635778bac7e46458392c1261e3916e8e9e86860
commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const
config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 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 <dan.carpenter@oracle.com>

smatch warnings:
lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'

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

a127b154a8f2317 Daniel Latypov 2021-09-14  57  static struct kunit_suite *
d2fbdde838f2703 Daniel Latypov 2022-05-16  58  kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
a127b154a8f2317 Daniel Latypov 2021-09-14  59  {
a127b154a8f2317 Daniel Latypov 2021-09-14  60  	int n = 0;
a127b154a8f2317 Daniel Latypov 2021-09-14  61  	struct kunit_case *filtered, *test_case;
a127b154a8f2317 Daniel Latypov 2021-09-14  62  	struct kunit_suite *copy;
a127b154a8f2317 Daniel Latypov 2021-09-14  63  
a127b154a8f2317 Daniel Latypov 2021-09-14  64  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f2317 Daniel Latypov 2021-09-14  65  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f2317 Daniel Latypov 2021-09-14  66  			++n;
a127b154a8f2317 Daniel Latypov 2021-09-14  67  	}
a127b154a8f2317 Daniel Latypov 2021-09-14  68  
a127b154a8f2317 Daniel Latypov 2021-09-14  69  	if (n == 0)
a127b154a8f2317 Daniel Latypov 2021-09-14  70  		return NULL;
a127b154a8f2317 Daniel Latypov 2021-09-14  71  
d2fbdde838f2703 Daniel Latypov 2022-05-16  72  	copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL);
a02353f491622e4 Daniel Latypov 2022-05-11  73  	if (!copy)
a02353f491622e4 Daniel Latypov 2022-05-11  74  		return ERR_PTR(-ENOMEM);
a127b154a8f2317 Daniel Latypov 2021-09-14  75  
a127b154a8f2317 Daniel Latypov 2021-09-14  76  	filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
a02353f491622e4 Daniel Latypov 2022-05-11  77  	if (!filtered)
a02353f491622e4 Daniel Latypov 2022-05-11 @78  		return ERR_PTR(-ENOMEM);

kfree(copy)?  Is the burden of random devs looking at this warning
forever more than the burden of adding a kfree()?  Hard to measure.

a127b154a8f2317 Daniel Latypov 2021-09-14  79  
a127b154a8f2317 Daniel Latypov 2021-09-14  80  	n = 0;
a127b154a8f2317 Daniel Latypov 2021-09-14  81  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f2317 Daniel Latypov 2021-09-14  82  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f2317 Daniel Latypov 2021-09-14  83  			filtered[n++] = *test_case;
a127b154a8f2317 Daniel Latypov 2021-09-14  84  	}
a127b154a8f2317 Daniel Latypov 2021-09-14  85  
a127b154a8f2317 Daniel Latypov 2021-09-14  86  	copy->test_cases = filtered;
a127b154a8f2317 Daniel Latypov 2021-09-14  87  	return copy;
a127b154a8f2317 Daniel Latypov 2021-09-14  88  }

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


WARNING: multiple messages have this Message-ID (diff)
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
Date: Sun, 10 Jul 2022 13:56:56 +0800	[thread overview]
Message-ID: <202207101328.ASjx88yj-lkp@intel.com> (raw)

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

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
CC: "GNU/Weeb Mailing List" <gwml@vger.gnuweeb.org>
CC: linux-kernel(a)vger.kernel.org
TO: Daniel Latypov <dlatypov@google.com>
CC: Shuah Khan <skhan@linuxfoundation.org>
CC: David Gow <davidgow@google.com>
CC: Brendan Higgins <brendanhiggins@google.com>

tree:   https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit
head:   7635778bac7e46458392c1261e3916e8e9e86860
commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp(a)intel.com/config)
compiler: arc-elf-gcc (GCC) 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 <dan.carpenter@oracle.com>

smatch warnings:
lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'

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

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

:::::: The code at line 78 was first introduced by commit
:::::: a02353f491622e49c7ddedc6a6dc4f1d6ed2150a kunit: bail out of test filtering logic quicker if OOM

:::::: TO: Daniel Latypov <dlatypov@google.com>
:::::: CC: Shuah Khan <skhan@linuxfoundation.org>

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

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
Date: Tue, 12 Jul 2022 15:50:49 +0300	[thread overview]
Message-ID: <202207101328.ASjx88yj-lkp@intel.com> (raw)

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

tree:   https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit
head:   7635778bac7e46458392c1261e3916e8e9e86860
commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const
config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp(a)intel.com/config)
compiler: arc-elf-gcc (GCC) 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 <dan.carpenter@oracle.com>

smatch warnings:
lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'

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

a127b154a8f2317 Daniel Latypov 2021-09-14  57  static struct kunit_suite *
d2fbdde838f2703 Daniel Latypov 2022-05-16  58  kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
a127b154a8f2317 Daniel Latypov 2021-09-14  59  {
a127b154a8f2317 Daniel Latypov 2021-09-14  60  	int n = 0;
a127b154a8f2317 Daniel Latypov 2021-09-14  61  	struct kunit_case *filtered, *test_case;
a127b154a8f2317 Daniel Latypov 2021-09-14  62  	struct kunit_suite *copy;
a127b154a8f2317 Daniel Latypov 2021-09-14  63  
a127b154a8f2317 Daniel Latypov 2021-09-14  64  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f2317 Daniel Latypov 2021-09-14  65  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f2317 Daniel Latypov 2021-09-14  66  			++n;
a127b154a8f2317 Daniel Latypov 2021-09-14  67  	}
a127b154a8f2317 Daniel Latypov 2021-09-14  68  
a127b154a8f2317 Daniel Latypov 2021-09-14  69  	if (n == 0)
a127b154a8f2317 Daniel Latypov 2021-09-14  70  		return NULL;
a127b154a8f2317 Daniel Latypov 2021-09-14  71  
d2fbdde838f2703 Daniel Latypov 2022-05-16  72  	copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL);
a02353f491622e4 Daniel Latypov 2022-05-11  73  	if (!copy)
a02353f491622e4 Daniel Latypov 2022-05-11  74  		return ERR_PTR(-ENOMEM);
a127b154a8f2317 Daniel Latypov 2021-09-14  75  
a127b154a8f2317 Daniel Latypov 2021-09-14  76  	filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
a02353f491622e4 Daniel Latypov 2022-05-11  77  	if (!filtered)
a02353f491622e4 Daniel Latypov 2022-05-11 @78  		return ERR_PTR(-ENOMEM);

kfree(copy)?  Is the burden of random devs looking at this warning
forever more than the burden of adding a kfree()?  Hard to measure.

a127b154a8f2317 Daniel Latypov 2021-09-14  79  
a127b154a8f2317 Daniel Latypov 2021-09-14  80  	n = 0;
a127b154a8f2317 Daniel Latypov 2021-09-14  81  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f2317 Daniel Latypov 2021-09-14  82  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f2317 Daniel Latypov 2021-09-14  83  			filtered[n++] = *test_case;
a127b154a8f2317 Daniel Latypov 2021-09-14  84  	}
a127b154a8f2317 Daniel Latypov 2021-09-14  85  
a127b154a8f2317 Daniel Latypov 2021-09-14  86  	copy->test_cases = filtered;
a127b154a8f2317 Daniel Latypov 2021-09-14  87  	return copy;
a127b154a8f2317 Daniel Latypov 2021-09-14  88  }

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

             reply	other threads:[~2022-07-12 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10  5:56 kernel test robot [this message]
2022-07-12 12:50 ` [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' Dan Carpenter
2022-07-12 12:50 ` Dan Carpenter
2022-07-12 13:29 ` David Gow
2022-07-12 13:29   ` David Gow

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=202207101328.ASjx88yj-lkp@intel.com \
    --to=dan.carpenter@oracle.com \
    --cc=brendanhiggins@google.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=gwml@vger.gnuweeb.org \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --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 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.