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. Signed-off-by: Maxime Ripard <mrip...@kernel.org> --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 23 +++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index a4eb68f0decca15988105b9d58266e3871934a8b..7f540f9e4d98cc507e51b486edb99177a23011d1 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -276,10 +276,33 @@ static void kunit_action_drm_mode_destroy(void *ptr) struct drm_display_mode *mode = 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 * @dev: DRM device * @video_code: CEA VIC of the mode diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index 11d59ce0bac0bbec07ae5f07ed9710cf01d73f09..1c62d1d4458cae3a6883a0daaf42b8431c4a213a 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -116,10 +116,13 @@ drm_kunit_helper_create_crtc(struct kunit *test, struct drm_plane *primary, struct drm_plane *cursor, 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); #endif // DRM_KUNIT_HELPERS_H_ -- 2.49.0