From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: thomas.hellstrom@linux.intel.com, dakr@kernel.org,
ecourtney@nvidia.com, matthew.brost@intel.com,
nat@pixelcluster.dev, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Subject: [PATCH 03/11] dma-buf/tests: Convert st-dma-resv tests to use dma_resv_alloc v2
Date: Thu, 3 Sep 2026 15:27:58 +0200 [thread overview]
Message-ID: <20260903134408.105317-4-christian.koenig@amd.com> (raw)
In-Reply-To: <20260903134408.105317-1-christian.koenig@amd.com>
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.
v2: add proper error handling when dma_resv_alloc() fails
Signed-off-by: Christian König <christian.koenig@amd.com>
Assisted-by: Claude:Sonnet 4
---
drivers/dma-buf/st-dma-resv.c | 102 +++++++++++++++++++++-------------
1 file changed, 62 insertions(+), 40 deletions(-)
diff --git a/drivers/dma-buf/st-dma-resv.c b/drivers/dma-buf/st-dma-resv.c
index 2c43d2d2b016..48c158cc5011 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,38 @@ 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();
+ if (!resv) {
+ KUNIT_FAIL(test, "Resv allocation failed");
+ goto err_free;
+ }
+
+ 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 +118,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 +126,28 @@ 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();
+ if (!resv) {
+ KUNIT_FAIL(test, "Resv allocation failed");
+ goto err_free;
+ }
+
+ 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 +170,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 +182,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 +190,30 @@ 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();
+ if (!resv) {
+ KUNIT_FAIL(test, "Resv allocation failed");
+ goto err_free;
+ }
+
+ 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 +248,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 +257,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 +265,29 @@ 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();
+ if (!resv) {
+ KUNIT_FAIL(test, "Resv allocation failed");
+ goto err_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 +304,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
next prev parent reply other threads:[~2026-09-03 13:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 13:27 Refcounting dma_resv v3 Christian König
2026-09-03 13:27 ` [PATCH 01/11] drm/i915: fix incorrect RCU teardown order Christian König
2026-09-03 13:27 ` [PATCH 02/11] dma-buf: Add reference counting to dma_resv v2 Christian König
2026-09-03 13:27 ` Christian König [this message]
2026-09-03 13:27 ` [PATCH 04/11] drm/gem: Add helper for drm_gem_object resv assignment v2 Christian König
2026-09-03 13:28 ` [PATCH 05/11] drm/gem: Convert drm_gem_private_object_init to return error code v2 Christian König
2026-09-03 13:28 ` [PATCH 06/11] drm/mode_config: Use dma_resv_alloc for lockdep annotation Christian König
2026-09-03 13:28 ` [PATCH 07/11] drm/xe: " Christian König
2026-09-03 13:28 ` [PATCH 08/11] drm/i915/gt: Use dma_resv_alloc for VM reservation objects v2 Christian König
2026-09-03 13:28 ` [PATCH 09/11] drm/ttm/tests: Use dma_resv_alloc in test files Christian König
2026-09-03 13:28 ` [PATCH 10/11] drm/gem: Use dynamic allocation for GEM object dma_resv Christian König
2026-09-03 13:28 ` [PATCH 11/11] dma-buf: Inline dma_resv_init and remove allocated flag Christian König
2026-09-03 19:38 ` Refcounting dma_resv v3 Matthew Brost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260903134408.105317-4-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=nat@pixelcluster.dev \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox