Skip to content

Commit 13c1d5f

Browse files
committed
drm/tests: helpers: Create kunit helper to destroy a drm_display_mode
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 <[email protected]> Link: https://lore.kernel.org/r/20250408-drm-kunit-drm-display-mode-memleak-v1-1-996305a2e75a@kernel.org Signed-off-by: Maxime Ripard <[email protected]>
1 parent 1260ed7 commit 13c1d5f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/gpu/drm/tests/drm_kunit_helpers.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,28 @@ static void kunit_action_drm_mode_destroy(void *ptr)
278278
drm_mode_destroy(NULL, mode);
279279
}
280280

281+
/**
282+
* drm_kunit_add_mode_destroy_action() - Add a drm_destroy_mode kunit action
283+
* @test: The test context object
284+
* @mode: The drm_display_mode to destroy eventually
285+
*
286+
* Registers a kunit action that will destroy the drm_display_mode at
287+
* the end of the test.
288+
*
289+
* If an error occurs, the drm_display_mode will be destroyed.
290+
*
291+
* Returns:
292+
* 0 on success, an error code otherwise.
293+
*/
294+
int drm_kunit_add_mode_destroy_action(struct kunit *test,
295+
struct drm_display_mode *mode)
296+
{
297+
return kunit_add_action_or_reset(test,
298+
kunit_action_drm_mode_destroy,
299+
mode);
300+
}
301+
EXPORT_SYMBOL_GPL(drm_kunit_add_mode_destroy_action);
302+
281303
/**
282304
* drm_kunit_display_mode_from_cea_vic() - return a mode for CEA VIC for a KUnit test
283305
* @test: The test context object

include/drm/drm_kunit_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ drm_kunit_helper_create_crtc(struct kunit *test,
118118
const struct drm_crtc_funcs *funcs,
119119
const struct drm_crtc_helper_funcs *helper_funcs);
120120

121+
int drm_kunit_add_mode_destroy_action(struct kunit *test,
122+
struct drm_display_mode *mode);
123+
121124
struct drm_display_mode *
122125
drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device *dev,
123126
u8 video_code);

0 commit comments

Comments
 (0)