Commit feba24de authored by Gerd Hoffmann's avatar Gerd Hoffmann

drm/qxl: add mode/framebuffer check functions

Add a helper functions to check video modes.  Also add a helper to check
framebuffer buffer objects, using the former for consistency.  That way
we should not fail in qxl_primary_atomic_check() because video modes
which are too big will not be added to the mode list in the first place.
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Acked-by: default avatarNoralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190118122020.27596-21-kraxel@redhat.com
parent 182e7f96
...@@ -190,6 +190,28 @@ void qxl_display_read_client_monitors_config(struct qxl_device *qdev) ...@@ -190,6 +190,28 @@ void qxl_display_read_client_monitors_config(struct qxl_device *qdev)
} }
} }
static int qxl_check_mode(struct qxl_device *qdev,
unsigned int width,
unsigned int height)
{
unsigned int stride;
unsigned int size;
if (check_mul_overflow(width, 4u, &stride))
return -EINVAL;
if (check_mul_overflow(stride, height, &size))
return -EINVAL;
if (size > qdev->vram_size)
return -ENOMEM;
return 0;
}
static int qxl_check_framebuffer(struct qxl_device *qdev,
struct qxl_bo *bo)
{
return qxl_check_mode(qdev, bo->surf.width, bo->surf.height);
}
static int qxl_add_monitors_config_modes(struct drm_connector *connector, static int qxl_add_monitors_config_modes(struct drm_connector *connector,
unsigned *pwidth, unsigned *pwidth,
unsigned *pheight) unsigned *pheight)
...@@ -469,12 +491,7 @@ static int qxl_primary_atomic_check(struct drm_plane *plane, ...@@ -469,12 +491,7 @@ static int qxl_primary_atomic_check(struct drm_plane *plane,
bo = gem_to_qxl_bo(state->fb->obj[0]); bo = gem_to_qxl_bo(state->fb->obj[0]);
if (bo->surf.stride * bo->surf.height > qdev->vram_size) { return qxl_check_framebuffer(qdev, bo);
DRM_ERROR("Mode doesn't fit in vram size (vgamem)");
return -EINVAL;
}
return 0;
} }
static int qxl_primary_apply_cursor(struct drm_plane *plane) static int qxl_primary_apply_cursor(struct drm_plane *plane)
...@@ -990,20 +1007,11 @@ static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector, ...@@ -990,20 +1007,11 @@ static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector,
{ {
struct drm_device *ddev = connector->dev; struct drm_device *ddev = connector->dev;
struct qxl_device *qdev = ddev->dev_private; struct qxl_device *qdev = ddev->dev_private;
int i;
/* TODO: is this called for user defined modes? (xrandr --add-mode)
* TODO: check that the mode fits in the framebuffer */
if (qdev->monitors_config_width == mode->hdisplay && if (qxl_check_mode(qdev, mode->hdisplay, mode->vdisplay) != 0)
qdev->monitors_config_height == mode->vdisplay) return MODE_BAD;
return MODE_OK;
for (i = 0; i < ARRAY_SIZE(common_modes); i++) { return MODE_OK;
if (common_modes[i].w == mode->hdisplay && common_modes[i].h == mode->vdisplay)
return MODE_OK;
}
return MODE_BAD;
} }
static struct drm_encoder *qxl_best_encoder(struct drm_connector *connector) static struct drm_encoder *qxl_best_encoder(struct drm_connector *connector)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment