Skip to content

Commit d5a0c81

Browse files
committed
drm: mxsfb: check framebuffer pitch
The lcdif IP does not support a framebuffer pitch (stride) other than framebuffer width. Check for equality and reject the framebuffer otherwise. This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tries to use a cache aligned stride, which leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly. Fixes: 45d59d7 ("drm: Add new driver for MXSFB controller") Signed-off-by: Stefan Agner <stefan@agner.ch> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200908141654.266836-1-stefan@agner.ch
1 parent dd42554 commit d5a0c81

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎drivers/gpu/drm/mxsfb/mxsfb_drv.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <drm/drm_connector.h>
2222
#include <drm/drm_drv.h>
2323
#include <drm/drm_fb_helper.h>
24+
#include <drm/drm_fourcc.h>
2425
#include <drm/drm_gem_cma_helper.h>
2526
#include <drm/drm_gem_framebuffer_helper.h>
2627
#include <drm/drm_irq.h>
@@ -81,8 +82,26 @@ void mxsfb_disable_axi_clk(struct mxsfb_drm_private *mxsfb)
8182
clk_disable_unprepare(mxsfb->clk_axi);
8283
}
8384

85+
static struct drm_framebuffer *
86+
mxsfb_fb_create(struct drm_device *dev, struct drm_file *file_priv,
87+
const struct drm_mode_fb_cmd2 *mode_cmd)
88+
{
89+
const struct drm_format_info *info;
90+
91+
info = drm_get_format_info(dev, mode_cmd);
92+
if (!info)
93+
return ERR_PTR(-EINVAL);
94+
95+
if (mode_cmd->width * info->cpp[0] != mode_cmd->pitches[0]) {
96+
dev_dbg(dev->dev, "Invalid pitch: fb width must match pitch\n");
97+
return ERR_PTR(-EINVAL);
98+
}
99+
100+
return drm_gem_fb_create(dev, file_priv, mode_cmd);
101+
}
102+
84103
static const struct drm_mode_config_funcs mxsfb_mode_config_funcs = {
85-
.fb_create = drm_gem_fb_create,
104+
.fb_create = mxsfb_fb_create,
86105
.atomic_check = drm_atomic_helper_check,
87106
.atomic_commit = drm_atomic_helper_commit,
88107
};

0 commit comments

Comments
 (0)