Skip to content

Commit 9521f9b

Browse files
committed
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
1 parent 23fd03a commit 9521f9b

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

drivers/gpu/drm/ast/ast_mode.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
#define AST_LUT_SIZE 256
5353

54+
#define AST_PRIMARY_PLANE_MAX_OFFSET (BIT(16) - 1)
55+
5456
static unsigned long ast_fb_vram_offset(void)
5557
{
5658
return 0; // with shmem, the primary plane is always at offset 0
@@ -960,16 +962,20 @@ static const struct drm_mode_config_helper_funcs ast_mode_config_helper_funcs =
960962
static enum drm_mode_status ast_mode_config_mode_valid(struct drm_device *dev,
961963
const struct drm_display_mode *mode)
962964
{
963-
static const unsigned long max_bpp = 4; /* DRM_FORMAT_XRGB8888 */
965+
const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB8888);
964966
struct ast_device *ast = to_ast_device(dev);
965-
unsigned long fbsize, fbpages, max_fbpages;
966-
967-
max_fbpages = ast_fb_vram_size(ast) >> PAGE_SHIFT;
968-
969-
fbsize = mode->hdisplay * mode->vdisplay * max_bpp;
970-
fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE);
971-
972-
if (fbpages > max_fbpages)
967+
unsigned long max_fb_size = ast_fb_vram_size(ast);
968+
u64 pitch;
969+
970+
if (drm_WARN_ON_ONCE(dev, !info))
971+
return MODE_ERROR; /* driver bug */
972+
973+
pitch = drm_format_info_min_pitch(info, 0, mode->hdisplay);
974+
if (!pitch)
975+
return MODE_BAD_WIDTH;
976+
if (pitch > AST_PRIMARY_PLANE_MAX_OFFSET)
977+
return MODE_BAD_WIDTH; /* maximum programmable pitch */
978+
if (pitch > max_fb_size / mode->vdisplay)
973979
return MODE_MEM;
974980

975981
return MODE_OK;

0 commit comments

Comments
 (0)