linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const
@ 2022-05-16 16:54 Daniel Latypov
  2022-05-18  7:59 ` David Gow
  2022-07-06 18:54 ` Brendan Higgins
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Latypov @ 2022-05-16 16:54 UTC (permalink / raw)
  To: brendanhiggins, davidgow
  Cc: linux-kernel, kunit-dev, linux-kselftest, skhan, Daniel Latypov,
	kernel test robot

kmemdup() is easier than kmalloc() + memcpy(), per lkp bot.

Also make the input `suite` as const since we're now always making
copies after commit a127b154a8f2 ("kunit: tool: allow filtering test
cases via glob").

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
---
 lib/kunit/executor.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 2f73a6a35a7e..43e15112460a 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -55,7 +55,7 @@ static void kunit_parse_filter_glob(struct kunit_test_filter *parsed,
 
 /* Create a copy of suite with only tests that match test_glob. */
 static struct kunit_suite *
-kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
+kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
 {
 	int n = 0;
 	struct kunit_case *filtered, *test_case;
@@ -69,11 +69,9 @@ kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
 	if (n == 0)
 		return NULL;
 
-	/* Use memcpy to workaround copy->name being const. */
-	copy = kmalloc(sizeof(*copy), GFP_KERNEL);
+	copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL);
 	if (!copy)
 		return ERR_PTR(-ENOMEM);
-	memcpy(copy, suite, sizeof(*copy));
 
 	filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
 	if (!filtered)

base-commit: 9660209d9418f2295d31fea0d32e313e9b2c1200
-- 
2.36.0.550.gb090851708-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const
  2022-05-16 16:54 [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const Daniel Latypov
@ 2022-05-18  7:59 ` David Gow
  2022-07-06 18:54 ` Brendan Higgins
  1 sibling, 0 replies; 3+ messages in thread
From: David Gow @ 2022-05-18  7:59 UTC (permalink / raw)
  To: Daniel Latypov
  Cc: Brendan Higgins, Linux Kernel Mailing List, KUnit Development,
	open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
	kernel test robot

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

On Tue, May 17, 2022 at 12:54 AM Daniel Latypov <dlatypov@google.com> wrote:
>
> kmemdup() is easier than kmalloc() + memcpy(), per lkp bot.
>
> Also make the input `suite` as const since we're now always making
> copies after commit a127b154a8f2 ("kunit: tool: allow filtering test
> cases via glob").
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>
> ---

Ah, this is definitely better. Thanks. I ran it under KASAN to double
check, and no issues there, either.

Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

>  lib/kunit/executor.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
> index 2f73a6a35a7e..43e15112460a 100644
> --- a/lib/kunit/executor.c
> +++ b/lib/kunit/executor.c
> @@ -55,7 +55,7 @@ static void kunit_parse_filter_glob(struct kunit_test_filter *parsed,
>
>  /* Create a copy of suite with only tests that match test_glob. */
>  static struct kunit_suite *
> -kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
> +kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
>  {
>         int n = 0;
>         struct kunit_case *filtered, *test_case;
> @@ -69,11 +69,9 @@ kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
>         if (n == 0)
>                 return NULL;
>
> -       /* Use memcpy to workaround copy->name being const. */
> -       copy = kmalloc(sizeof(*copy), GFP_KERNEL);
> +       copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL);
>         if (!copy)
>                 return ERR_PTR(-ENOMEM);
> -       memcpy(copy, suite, sizeof(*copy));
>
>         filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
>         if (!filtered)
>
> base-commit: 9660209d9418f2295d31fea0d32e313e9b2c1200
> --
> 2.36.0.550.gb090851708-goog
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4003 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const
  2022-05-16 16:54 [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const Daniel Latypov
  2022-05-18  7:59 ` David Gow
@ 2022-07-06 18:54 ` Brendan Higgins
  1 sibling, 0 replies; 3+ messages in thread
From: Brendan Higgins @ 2022-07-06 18:54 UTC (permalink / raw)
  To: Daniel Latypov
  Cc: davidgow, linux-kernel, kunit-dev, linux-kselftest, skhan,
	kernel test robot

On Mon, May 16, 2022 at 12:54 PM Daniel Latypov <dlatypov@google.com> wrote:
>
> kmemdup() is easier than kmalloc() + memcpy(), per lkp bot.
>
> Also make the input `suite` as const since we're now always making
> copies after commit a127b154a8f2 ("kunit: tool: allow filtering test
> cases via glob").
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-06 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 16:54 [PATCH] kunit: use kmemdup in kunit_filter_tests(), take suite as const Daniel Latypov
2022-05-18  7:59 ` David Gow
2022-07-06 18:54 ` Brendan Higgins

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).