Skip to content

Commit caa714f

Browse files
Jinjie Ruanmripard
authored andcommitted
drm/tests: helpers: Add helper for drm_display_mode_from_cea_vic()
As Maxime suggested, add a new helper drm_kunit_display_mode_from_cea_vic(), it can replace the direct call of drm_display_mode_from_cea_vic(), and it will help solving the `mode` memory leaks. Acked-by: Maxime Ripard <[email protected]> Suggested-by: Maxime Ripard <[email protected]> Signed-off-by: Jinjie Ruan <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Maxime Ripard <[email protected]>
1 parent 4700fd3 commit caa714f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/gpu/drm/tests/drm_kunit_helpers.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <drm/drm_atomic.h>
44
#include <drm/drm_atomic_helper.h>
55
#include <drm/drm_drv.h>
6+
#include <drm/drm_edid.h>
67
#include <drm/drm_fourcc.h>
78
#include <drm/drm_kunit_helpers.h>
89
#include <drm/drm_managed.h>
@@ -311,6 +312,47 @@ drm_kunit_helper_create_crtc(struct kunit *test,
311312
}
312313
EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc);
313314

315+
static void kunit_action_drm_mode_destroy(void *ptr)
316+
{
317+
struct drm_display_mode *mode = ptr;
318+
319+
drm_mode_destroy(NULL, mode);
320+
}
321+
322+
/**
323+
* drm_kunit_display_mode_from_cea_vic() - return a mode for CEA VIC
324+
for a KUnit test
325+
* @test: The test context object
326+
* @dev: DRM device
327+
* @video_code: CEA VIC of the mode
328+
*
329+
* Creates a new mode matching the specified CEA VIC for a KUnit test.
330+
*
331+
* Resources will be cleaned up automatically.
332+
*
333+
* Returns: A new drm_display_mode on success or NULL on failure
334+
*/
335+
struct drm_display_mode *
336+
drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device *dev,
337+
u8 video_code)
338+
{
339+
struct drm_display_mode *mode;
340+
int ret;
341+
342+
mode = drm_display_mode_from_cea_vic(dev, video_code);
343+
if (!mode)
344+
return NULL;
345+
346+
ret = kunit_add_action_or_reset(test,
347+
kunit_action_drm_mode_destroy,
348+
mode);
349+
if (ret)
350+
return NULL;
351+
352+
return mode;
353+
}
354+
EXPORT_SYMBOL_GPL(drm_kunit_display_mode_from_cea_vic);
355+
314356
MODULE_AUTHOR("Maxime Ripard <[email protected]>");
315357
MODULE_DESCRIPTION("KUnit test suite helper functions");
316358
MODULE_LICENSE("GPL");

include/drm/drm_kunit_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,8 @@ drm_kunit_helper_create_crtc(struct kunit *test,
120120
const struct drm_crtc_funcs *funcs,
121121
const struct drm_crtc_helper_funcs *helper_funcs);
122122

123+
struct drm_display_mode *
124+
drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device *dev,
125+
u8 video_code);
126+
123127
#endif // DRM_KUNIT_HELPERS_H_

0 commit comments

Comments
 (0)