diff options
author | Daniel Latypov <dlatypov@google.com> | 2022-07-22 17:15:32 +0000 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2022-10-07 10:15:44 -0600 |
commit | 047a8a0a2da716fecfd325d21ccf509c431992d9 (patch) | |
tree | e437da59bc25dfba6f15fe8c6a4864f1ca6b4d48 /lib/math | |
parent | 4db4598b5ed8fc26f5fd9312623a9ec5cebbe74a (diff) |
kunit: make kunit_kfree() only work on pointers from kunit_malloc() and friends
kunit_kfree() exists to clean up allocations from kunit_kmalloc() and
friends early instead of waiting for this to happen automatically at the
end of the test.
But it can be used on *anything* registered with the kunit resource API.
E.g. the last 2 statements are equivalent:
struct kunit_resource *res = something();
kfree(res->data);
kunit_put_resource(res);
The problem is that there could be multiple resources that point to the
same `data`.
E.g. you can have a named resource acting as a pseudo-global variable in
a test. If you point it to data allocated with kunit_kmalloc(), then
calling `kunit_kfree(ptr)` has the chance to delete either the named
resource or to kfree `ptr`.
Which one it does depends on the order the resources are registered as
kunit_kfree() will delete resources in LIFO order.
So this patch restricts kunit_kfree() to only working on resources
created by kunit_kmalloc(). Calling it is therefore guaranteed to free
the memory, not do anything else.
Note: kunit_resource_instance_match() wasn't used outside of KUnit, so
it should be safe to remove from the public interface. It's also
generally dangerous, as shown above, and shouldn't be used.
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>
Diffstat (limited to 'lib/math')
0 files changed, 0 insertions, 0 deletions