]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/tests: helpers: Create kunit helper to destroy a drm_display_mode
authorMaxime Ripard <mripard@kernel.org>
Tue, 8 Apr 2025 07:34:07 +0000 (09:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:08 +0000 (10:45 +0200)
[ Upstream commit 13c1d5f3a7fa7b55a26e73bb9e95342374a489b2 ]

A number of test suites call functions that expect the returned
drm_display_mode to be destroyed eventually.

However, none of the tests called drm_mode_destroy, which results in a
memory leak.

Since drm_mode_destroy takes two pointers as argument, we can't use a
kunit wrapper. Let's just create a helper every test suite can use.

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20250408-drm-kunit-drm-display-mode-memleak-v1-1-996305a2e75a@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Stable-dep-of: 70f29ca3117a ("drm/tests: cmdline: Fix drm_display_mode memory leak")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/tests/drm_kunit_helpers.c
include/drm/drm_kunit_helpers.h

index 12d58353a54ef487e229691da2be45ddb28a8880..04d98f81c522775cd878cc398b1e05b630f7309b 100644 (file)
@@ -391,6 +391,28 @@ static void kunit_action_drm_mode_destroy(void *ptr)
        drm_mode_destroy(NULL, mode);
 }
 
+/**
+ * drm_kunit_add_mode_destroy_action() - Add a drm_destroy_mode kunit action
+ * @test: The test context object
+ * @mode: The drm_display_mode to destroy eventually
+ *
+ * Registers a kunit action that will destroy the drm_display_mode at
+ * the end of the test.
+ *
+ * If an error occurs, the drm_display_mode will be destroyed.
+ *
+ * Returns:
+ * 0 on success, an error code otherwise.
+ */
+int drm_kunit_add_mode_destroy_action(struct kunit *test,
+                                     struct drm_display_mode *mode)
+{
+       return kunit_add_action_or_reset(test,
+                                        kunit_action_drm_mode_destroy,
+                                        mode);
+}
+EXPORT_SYMBOL_GPL(drm_kunit_add_mode_destroy_action);
+
 /**
  * drm_kunit_display_mode_from_cea_vic() - return a mode for CEA VIC for a KUnit test
  * @test: The test context object
index 3e5f4a23685efae863e7319aa64e9dcb4d901ee2..07e9a451262b66ec0b9350a5d442d88c7ec46d87 100644 (file)
@@ -120,6 +120,9 @@ drm_kunit_helper_create_crtc(struct kunit *test,
                             const struct drm_crtc_funcs *funcs,
                             const struct drm_crtc_helper_funcs *helper_funcs);
 
+int drm_kunit_add_mode_destroy_action(struct kunit *test,
+                                     struct drm_display_mode *mode);
+
 struct drm_display_mode *
 drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device *dev,
                                    u8 video_code);