Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Permanent memory leak of dynamically allocated `dma_resv` objects in 
test files due to unmanaged allocations without proper cleanup on success and 
error paths.
--

commit 12a4cfd4069727fd22b42f06cb1cc43d2134b9c2
Author: Christian König <[email protected]>

drm/ttm/tests: Use dma_resv_alloc in test files

This commit replaces dma_resv_init usage with dma_resv_alloc() in the TTM
test files, moving away from embedded structures to reference-counted
dynamic allocations.

> --- a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> @@ -339,14 +339,12 @@ static void ttm_bo_unreserve_bulk(struct kunit *test)
[ ... ]
>       err = ttm_device_kunit_init(priv, ttm_dev, 0);
>       KUNIT_ASSERT_EQ(test, err, 0);
>       priv->ttm_dev = ttm_dev;
>  
> -     dma_resv_init(resv);
> +     resv = dma_resv_alloc();
> +     KUNIT_ASSERT_NOT_NULL(test, resv);
>  
>       bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, resv);
>       bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, resv);

[Severity: Medium]
Does this leak the dynamically allocated dma_resv object?

Because resv is no longer KUnit-managed, and both bo1 and bo2 take references
to it via ttm_bo_kunit_init(), it seems the object will never be fully freed. 
While this function has a dma_resv_put(resv) at the end, bo1 and bo2 are 
never explicitly destroyed (e.g., via ttm_bo_fini() as seen in other tests),
leaving the refcount elevated on the success path.

> @@ -441,11 +439,9 @@ static void ttm_bo_fini_shared_resv(struct kunit *test)
>       KUNIT_ASSERT_EQ(test, err, 0);
>       priv->ttm_dev = ttm_dev;
>  
> -     external_resv = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL);
> +     external_resv = dma_resv_alloc();
>       KUNIT_ASSERT_NOT_NULL(test, external_resv);
>  
> -     dma_resv_init(external_resv);
> -
>       fence = kunit_kzalloc(test, sizeof(*fence), GFP_KERNEL);
>       KUNIT_ASSERT_NOT_NULL(test, fence);

[Severity: Medium]
Can this leak external_resv on the error path?

If the kunit_kzalloc() for the fence fails, the KUNIT_ASSERT_NOT_NULL() macro 
will abort the test thread immediately. This bypasses the explicit 
dma_resv_put(external_resv) cleanup at the end of the function, leaking the
unmanaged allocation.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=9

Reply via email to