Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/ast: Validate display modes against framebuffer and format limits

Reimplement ast_mode_config_mode_valid() with DRM format helpers and
ast's helpers for framebuffer size calculation. Replaces ast's open-
coded assumptions on bpp and page-alignments.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/r/20250324094520.192974-4-tzimmermann@suse.de

+13 -7
+13 -7
drivers/gpu/drm/ast/ast_mode.c
··· 51 51 52 52 #define AST_LUT_SIZE 256 53 53 54 + #define AST_PRIMARY_PLANE_MAX_OFFSET (BIT(16) - 1) 55 + 54 56 static unsigned long ast_fb_vram_offset(void) 55 57 { 56 58 return 0; // with shmem, the primary plane is always at offset 0 ··· 962 960 static enum drm_mode_status ast_mode_config_mode_valid(struct drm_device *dev, 963 961 const struct drm_display_mode *mode) 964 962 { 965 - static const unsigned long max_bpp = 4; /* DRM_FORMAT_XRGB8888 */ 963 + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB8888); 966 964 struct ast_device *ast = to_ast_device(dev); 967 - unsigned long fbsize, fbpages, max_fbpages; 965 + unsigned long max_fb_size = ast_fb_vram_size(ast); 966 + u64 pitch; 968 967 969 - max_fbpages = ast_fb_vram_size(ast) >> PAGE_SHIFT; 968 + if (drm_WARN_ON_ONCE(dev, !info)) 969 + return MODE_ERROR; /* driver bug */ 970 970 971 - fbsize = mode->hdisplay * mode->vdisplay * max_bpp; 972 - fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE); 973 - 974 - if (fbpages > max_fbpages) 971 + pitch = drm_format_info_min_pitch(info, 0, mode->hdisplay); 972 + if (!pitch) 973 + return MODE_BAD_WIDTH; 974 + if (pitch > AST_PRIMARY_PLANE_MAX_OFFSET) 975 + return MODE_BAD_WIDTH; /* maximum programmable pitch */ 976 + if (pitch > max_fb_size / mode->vdisplay) 975 977 return MODE_MEM; 976 978 977 979 return MODE_OK;