]> git.baikalelectronics.ru Git - kernel.git/commit
kunit: make kunit_kfree(NULL) a no-op to match kfree()
authorDaniel Latypov <dlatypov@google.com>
Fri, 22 Jul 2022 17:15:34 +0000 (17:15 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 7 Oct 2022 16:15:56 +0000 (10:15 -0600)
commitcdae43026ce430f7f50b7695b930527877cf6369
treea410492b1fb6ccdfef80f39c916cb02fe697ac2c
parentf5a9f6f5f09708942e51f8fc791868a335ccd5e7
kunit: make kunit_kfree(NULL) a no-op to match kfree()

The real kfree() function will silently return when given a NULL.
So a user might reasonably think they can write the following code:
  char *buffer = NULL;
  if (param->use_buffer) buffer = kunit_kzalloc(test, 10, GFP_KERNEL);
  ...
  kunit_kfree(test, buffer);

As-is, kunit_kfree() will mark the test as FAILED when buffer is NULL.
(And in earlier times, it would segfault).

Let's match the semantics of kfree().

Suggested-by: David Gow <davidgow@google.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/test.c