Automatically unpin pages on cleanup. The test currently fails with
the error

[   58.246263] drm-kunit-mock-device 
drm_gem_shmem_test_get_sg_table.drm-kunit-mock-device: [drm] 
drm_WARN_ON(refcount_read(&shmem->pages_pin_count))

while cleaning up the GEM object. The pin count has to be zero at this
point.

Signed-off-by: Thomas Zimmermann <[email protected]>
Fixes: d586b535f144 ("drm/shmem-helper: Add and use pages_pin_count")
Cc: [email protected]
Cc: <[email protected]> # v6.16+
---
 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_gem_shmem_test.c 
b/drivers/gpu/drm/tests/drm_gem_shmem_test.c
index 872881ec9c30..1d50bab51ef3 100644
--- a/drivers/gpu/drm/tests/drm_gem_shmem_test.c
+++ b/drivers/gpu/drm/tests/drm_gem_shmem_test.c
@@ -34,6 +34,9 @@ KUNIT_DEFINE_ACTION_WRAPPER(sg_free_table_wrapper, 
sg_free_table,
 KUNIT_DEFINE_ACTION_WRAPPER(drm_gem_shmem_free_wrapper, drm_gem_shmem_free,
                            struct drm_gem_shmem_object *);
 
+KUNIT_DEFINE_ACTION_WRAPPER(drm_gem_shmem_unpin_wrapper, drm_gem_shmem_unpin,
+                           struct drm_gem_shmem_object *);
+
 /*
  * Test creating a shmem GEM object backed by shmem buffer. The test
  * case succeeds if the GEM object is successfully allocated with the
@@ -212,6 +215,9 @@ static void drm_gem_shmem_test_get_sg_table(struct kunit 
*test)
        ret = drm_gem_shmem_pin(shmem);
        KUNIT_ASSERT_EQ(test, ret, 0);
 
+       ret = kunit_add_action_or_reset(test, drm_gem_shmem_unpin_wrapper, 
shmem);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
        sgt = drm_gem_shmem_get_sg_table(shmem);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt);
        KUNIT_EXPECT_NULL(test, shmem->sgt);
-- 
2.52.0

Reply via email to