mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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 <mripard@kernel.org> Suggested-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241030023504.530425-2-ruanjinjie@huawei.com Signed-off-by: Maxime Ripard <mripard@kernel.org>
This commit is contained in:
		
							parent
							
								
									4700fd3e05
								
							
						
					
					
						commit
						caa714f866
					
				
					 2 changed files with 46 additions and 0 deletions
				
			
		| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include <drm/drm_atomic.h>
 | 
					#include <drm/drm_atomic.h>
 | 
				
			||||||
#include <drm/drm_atomic_helper.h>
 | 
					#include <drm/drm_atomic_helper.h>
 | 
				
			||||||
#include <drm/drm_drv.h>
 | 
					#include <drm/drm_drv.h>
 | 
				
			||||||
 | 
					#include <drm/drm_edid.h>
 | 
				
			||||||
#include <drm/drm_fourcc.h>
 | 
					#include <drm/drm_fourcc.h>
 | 
				
			||||||
#include <drm/drm_kunit_helpers.h>
 | 
					#include <drm/drm_kunit_helpers.h>
 | 
				
			||||||
#include <drm/drm_managed.h>
 | 
					#include <drm/drm_managed.h>
 | 
				
			||||||
| 
						 | 
					@ -311,6 +312,47 @@ drm_kunit_helper_create_crtc(struct kunit *test,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc);
 | 
					EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void kunit_action_drm_mode_destroy(void *ptr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct drm_display_mode *mode = ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						drm_mode_destroy(NULL, mode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 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
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Creates a new mode matching the specified CEA VIC for a KUnit test.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Resources will be cleaned up automatically.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Returns: A new drm_display_mode on success or NULL on failure
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct drm_display_mode *
 | 
				
			||||||
 | 
					drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device *dev,
 | 
				
			||||||
 | 
									    u8 video_code)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct drm_display_mode *mode;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mode = drm_display_mode_from_cea_vic(dev, video_code);
 | 
				
			||||||
 | 
						if (!mode)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = kunit_add_action_or_reset(test,
 | 
				
			||||||
 | 
										kunit_action_drm_mode_destroy,
 | 
				
			||||||
 | 
										mode);
 | 
				
			||||||
 | 
						if (ret)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return mode;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(drm_kunit_display_mode_from_cea_vic);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
 | 
					MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
 | 
				
			||||||
MODULE_DESCRIPTION("KUnit test suite helper functions");
 | 
					MODULE_DESCRIPTION("KUnit test suite helper functions");
 | 
				
			||||||
MODULE_LICENSE("GPL");
 | 
					MODULE_LICENSE("GPL");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,4 +120,8 @@ drm_kunit_helper_create_crtc(struct kunit *test,
 | 
				
			||||||
			     const struct drm_crtc_funcs *funcs,
 | 
								     const struct drm_crtc_funcs *funcs,
 | 
				
			||||||
			     const struct drm_crtc_helper_funcs *helper_funcs);
 | 
								     const struct drm_crtc_helper_funcs *helper_funcs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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_
 | 
					#endif // DRM_KUNIT_HELPERS_H_
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue