提交 f62314b1 编写于 作者: X Xiyu Yang 提交者: Shuah Khan

kunit: fix reference count leak in kfree_at_end

The reference counting issue happens in the normal path of
kfree_at_end(). When kunit_alloc_and_get_resource() is invoked, the
function forgets to handle the returned resource object, whose refcount
increased inside, causing a refcount leak.

Fix this issue by calling kunit_alloc_resource() instead of
kunit_alloc_and_get_resource().

Fixed the following when applying:
Shuah Khan <skhan@linuxfoundation.org>

CHECK: Alignment should match open parenthesis
+	kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL,
 				     (void *)to_free);
Signed-off-by: NXiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: NXin Tan <tanxin.ctf@gmail.com>
Reviewed-by: NDaniel Latypov <dlatypov@google.com>
Reviewed-by: NBrendan Higgins <brendanhiggins@google.com>
Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
上级 d8c23ead
...@@ -116,8 +116,8 @@ static void kfree_at_end(struct kunit *test, const void *to_free) ...@@ -116,8 +116,8 @@ static void kfree_at_end(struct kunit *test, const void *to_free)
/* kfree() handles NULL already, but avoid allocating a no-op cleanup. */ /* kfree() handles NULL already, but avoid allocating a no-op cleanup. */
if (IS_ERR_OR_NULL(to_free)) if (IS_ERR_OR_NULL(to_free))
return; return;
kunit_alloc_and_get_resource(test, NULL, kfree_res_free, GFP_KERNEL, kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL,
(void *)to_free); (void *)to_free);
} }
static struct kunit_suite *alloc_fake_suite(struct kunit *test, static struct kunit_suite *alloc_fake_suite(struct kunit *test,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册