Update all test cases in st-dma-resv.c to use the new dma_resv_alloc()
API instead of stack-allocating dma_resv objects. This demonstrates the
proper usage of the new allocation and reference counting interface.

All five test functions now:
- Use dma_resv_alloc() to allocate objects
- Check for allocation failure with KUNIT_ASSERT_NOT_NULL
- Clean up with dma_resv_put() which handles freeing

This change also provides better test coverage for the reference
counting implementation.

Signed-off-by: Christian König <[email protected]>
Assisted-by: Claude:Sonnet 4
---
 drivers/dma-buf/st-dma-resv.c | 90 +++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 40 deletions(-)

diff --git a/drivers/dma-buf/st-dma-resv.c b/drivers/dma-buf/st-dma-resv.c
index 2c43d2d2b0169..b843d90417822 100644
--- a/drivers/dma-buf/st-dma-resv.c
+++ b/drivers/dma-buf/st-dma-resv.c
@@ -41,7 +41,7 @@ static struct dma_fence *alloc_fence(void)
 
 static void test_sanitycheck(struct kunit *test)
 {
-       struct dma_resv resv;
+       struct dma_resv *resv;
        struct dma_fence *f;
        int r;
 
@@ -53,20 +53,22 @@ static void test_sanitycheck(struct kunit *test)
        dma_fence_signal(f);
        dma_fence_put(f);
 
-       dma_resv_init(&resv);
-       r = dma_resv_lock(&resv, NULL);
+       resv = dma_resv_alloc();
+       KUNIT_ASSERT_NOT_NULL(test, resv);
+
+       r = dma_resv_lock(resv, NULL);
        if (r)
                KUNIT_FAIL(test, "Resv locking failed\n");
        else
-               dma_resv_unlock(&resv);
-       dma_resv_put(&resv);
+               dma_resv_unlock(resv);
+       dma_resv_put(resv);
 }
 
 static void test_signaling(struct kunit *test)
 {
        const struct dma_resv_usage_param *param = test->param_value;
        enum dma_resv_usage usage = param->usage;
-       struct dma_resv resv;
+       struct dma_resv *resv;
        struct dma_fence *f;
        int r;
 
@@ -75,33 +77,35 @@ static void test_signaling(struct kunit *test)
 
        dma_fence_enable_signaling(f);
 
-       dma_resv_init(&resv);
-       r = dma_resv_lock(&resv, NULL);
+       resv = dma_resv_alloc();
+       KUNIT_ASSERT_NOT_NULL(test, resv);
+
+       r = dma_resv_lock(resv, NULL);
        if (r) {
                KUNIT_FAIL(test, "Resv locking failed");
                goto err_free;
        }
 
-       r = dma_resv_reserve_fences(&resv, 1);
+       r = dma_resv_reserve_fences(resv, 1);
        if (r) {
                KUNIT_FAIL(test, "Resv shared slot allocation failed");
                goto err_unlock;
        }
 
-       dma_resv_add_fence(&resv, f, usage);
-       if (dma_resv_test_signaled(&resv, usage)) {
+       dma_resv_add_fence(resv, f, usage);
+       if (dma_resv_test_signaled(resv, usage)) {
                KUNIT_FAIL(test, "Resv unexpectedly signaled");
                goto err_unlock;
        }
        dma_fence_signal(f);
-       if (!dma_resv_test_signaled(&resv, usage)) {
+       if (!dma_resv_test_signaled(resv, usage)) {
                KUNIT_FAIL(test, "Resv not reporting signaled");
                goto err_unlock;
        }
 err_unlock:
-       dma_resv_unlock(&resv);
+       dma_resv_unlock(resv);
 err_free:
-       dma_resv_put(&resv);
+       dma_resv_put(resv);
        dma_fence_put(f);
 }
 
@@ -111,7 +115,7 @@ static void test_for_each(struct kunit *test)
        enum dma_resv_usage usage = param->usage;
        struct dma_resv_iter cursor;
        struct dma_fence *f, *fence;
-       struct dma_resv resv;
+       struct dma_resv *resv;
        int r;
 
        f = alloc_fence();
@@ -119,23 +123,25 @@ static void test_for_each(struct kunit *test)
 
        dma_fence_enable_signaling(f);
 
-       dma_resv_init(&resv);
-       r = dma_resv_lock(&resv, NULL);
+       resv = dma_resv_alloc();
+       KUNIT_ASSERT_NOT_NULL(test, resv);
+
+       r = dma_resv_lock(resv, NULL);
        if (r) {
                KUNIT_FAIL(test, "Resv locking failed");
                goto err_free;
        }
 
-       r = dma_resv_reserve_fences(&resv, 1);
+       r = dma_resv_reserve_fences(resv, 1);
        if (r) {
                KUNIT_FAIL(test, "Resv shared slot allocation failed");
                goto err_unlock;
        }
 
-       dma_resv_add_fence(&resv, f, usage);
+       dma_resv_add_fence(resv, f, usage);
 
        r = -ENOENT;
-       dma_resv_for_each_fence(&cursor, &resv, usage, fence) {
+       dma_resv_for_each_fence(&cursor, resv, usage, fence) {
                if (!r) {
                        KUNIT_FAIL(test, "More than one fence found");
                        goto err_unlock;
@@ -158,9 +164,9 @@ static void test_for_each(struct kunit *test)
        }
        dma_fence_signal(f);
 err_unlock:
-       dma_resv_unlock(&resv);
+       dma_resv_unlock(resv);
 err_free:
-       dma_resv_put(&resv);
+       dma_resv_put(resv);
        dma_fence_put(f);
 }
 
@@ -170,7 +176,7 @@ static void test_for_each_unlocked(struct kunit *test)
        enum dma_resv_usage usage = param->usage;
        struct dma_resv_iter cursor;
        struct dma_fence *f, *fence;
-       struct dma_resv resv;
+       struct dma_resv *resv;
        int r;
 
        f = alloc_fence();
@@ -178,25 +184,27 @@ static void test_for_each_unlocked(struct kunit *test)
 
        dma_fence_enable_signaling(f);
 
-       dma_resv_init(&resv);
-       r = dma_resv_lock(&resv, NULL);
+       resv = dma_resv_alloc();
+       KUNIT_ASSERT_NOT_NULL(test, resv);
+
+       r = dma_resv_lock(resv, NULL);
        if (r) {
                KUNIT_FAIL(test, "Resv locking failed");
                goto err_free;
        }
 
-       r = dma_resv_reserve_fences(&resv, 1);
+       r = dma_resv_reserve_fences(resv, 1);
        if (r) {
                KUNIT_FAIL(test, "Resv shared slot allocation failed");
-               dma_resv_unlock(&resv);
+               dma_resv_unlock(resv);
                goto err_free;
        }
 
-       dma_resv_add_fence(&resv, f, usage);
-       dma_resv_unlock(&resv);
+       dma_resv_add_fence(resv, f, usage);
+       dma_resv_unlock(resv);
 
        r = -ENOENT;
-       dma_resv_iter_begin(&cursor, &resv, usage);
+       dma_resv_iter_begin(&cursor, resv, usage);
        dma_resv_for_each_fence_unlocked(&cursor, fence) {
                if (!r) {
                        KUNIT_FAIL(test, "More than one fence found");
@@ -231,7 +239,7 @@ static void test_for_each_unlocked(struct kunit *test)
        dma_resv_iter_end(&cursor);
        dma_fence_signal(f);
 err_free:
-       dma_resv_put(&resv);
+       dma_resv_put(resv);
        dma_fence_put(f);
 }
 
@@ -240,7 +248,7 @@ static void test_get_fences(struct kunit *test)
        const struct dma_resv_usage_param *param = test->param_value;
        enum dma_resv_usage usage = param->usage;
        struct dma_fence *f, **fences = NULL;
-       struct dma_resv resv;
+       struct dma_resv *resv;
        int r, i;
 
        f = alloc_fence();
@@ -248,24 +256,26 @@ static void test_get_fences(struct kunit *test)
 
        dma_fence_enable_signaling(f);
 
-       dma_resv_init(&resv);
-       r = dma_resv_lock(&resv, NULL);
+       resv = dma_resv_alloc();
+       KUNIT_ASSERT_NOT_NULL(test, resv);
+
+       r = dma_resv_lock(resv, NULL);
        if (r) {
                KUNIT_FAIL(test, "Resv locking failed");
                goto err_resv;
        }
 
-       r = dma_resv_reserve_fences(&resv, 1);
+       r = dma_resv_reserve_fences(resv, 1);
        if (r) {
                KUNIT_FAIL(test, "Resv shared slot allocation failed");
-               dma_resv_unlock(&resv);
+               dma_resv_unlock(resv);
                goto err_resv;
        }
 
-       dma_resv_add_fence(&resv, f, usage);
-       dma_resv_unlock(&resv);
+       dma_resv_add_fence(resv, f, usage);
+       dma_resv_unlock(resv);
 
-       r = dma_resv_get_fences(&resv, usage, &i, &fences);
+       r = dma_resv_get_fences(resv, usage, &i, &fences);
        if (r) {
                KUNIT_FAIL(test, "get_fences failed");
                goto err_free;
@@ -282,7 +292,7 @@ static void test_get_fences(struct kunit *test)
                dma_fence_put(fences[i]);
        kfree(fences);
 err_resv:
-       dma_resv_put(&resv);
+       dma_resv_put(resv);
        dma_fence_put(f);
 }
 
-- 
2.43.0

Reply via email to