drm/vc4: tests: mock: Use a kunit action to unregister DRM device
authorMaxime Ripard <mripard@kernel.org>
Fri, 28 Jul 2023 09:06:21 +0000 (11:06 +0200)
committerMaxime Ripard <mripard@kernel.org>
Mon, 31 Jul 2023 12:19:57 +0000 (14:19 +0200)
The *_mock_device functions allocate a DRM device that needs to be
released using drm_dev_unregister.

Now that we have a kunit release action API, we can switch to it and
don't require any kind of garbage collection from the caller.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: MaĆ­ra Canal <mairacanal@riseup.net>
Link: https://lore.kernel.org/r/20230728-kms-kunit-actions-rework-v3-8-952565ccccfe@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
drivers/gpu/drm/vc4/tests/vc4_mock.c
drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c

index a4bed26..63ca46f 100644 (file)
@@ -153,6 +153,13 @@ static int __build_mock(struct kunit *test, struct drm_device *drm,
        return 0;
 }
 
+static void kunit_action_drm_dev_unregister(void *ptr)
+{
+       struct drm_device *drm = ptr;
+
+       drm_dev_unregister(drm);
+}
+
 static struct vc4_dev *__mock_device(struct kunit *test, bool is_vc5)
 {
        struct drm_device *drm;
@@ -186,6 +193,11 @@ static struct vc4_dev *__mock_device(struct kunit *test, bool is_vc5)
        ret = drm_dev_register(drm, 0);
        KUNIT_ASSERT_EQ(test, ret, 0);
 
+       ret = kunit_add_action_or_reset(test,
+                                       kunit_action_drm_dev_unregister,
+                                       drm);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
        return vc4;
 }
 
index 6c982e7..776a7b0 100644 (file)
@@ -754,14 +754,11 @@ static int vc4_pv_muxing_test_init(struct kunit *test)
 static void vc4_pv_muxing_test_exit(struct kunit *test)
 {
        struct pv_muxing_priv *priv = test->priv;
-       struct vc4_dev *vc4 = priv->vc4;
-       struct drm_device *drm = &vc4->base;
        struct drm_atomic_state *state = priv->state;
 
        drm_atomic_state_put(state);
        drm_modeset_drop_locks(&priv->ctx);
        drm_modeset_acquire_fini(&priv->ctx);
-       drm_dev_unregister(drm);
 }
 
 static struct kunit_case vc4_pv_muxing_tests[] = {
@@ -871,7 +868,6 @@ static void drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable(struct kunit *tes
        drm_atomic_state_put(state);
        drm_modeset_drop_locks(&ctx);
        drm_modeset_acquire_fini(&ctx);
-       drm_dev_unregister(drm);
 }
 
 static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test)
@@ -960,7 +956,6 @@ static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test)
        drm_atomic_state_put(state);
        drm_modeset_drop_locks(&ctx);
        drm_modeset_acquire_fini(&ctx);
-       drm_dev_unregister(drm);
 }
 
 static void
@@ -1013,7 +1008,6 @@ drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state(struct ku
        drm_atomic_state_put(state);
        drm_modeset_drop_locks(&ctx);
        drm_modeset_acquire_fini(&ctx);
-       drm_dev_unregister(drm);
 }
 
 static struct kunit_case vc5_pv_muxing_bugs_tests[] = {