Skip to content

Commit 52e4b24

Browse files
agnersgregkh
authored andcommitted
drm: mxsfb: check framebuffer pitch
[ Upstream commit d5a0c81 ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ca0b860 commit 52e4b24

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
@@ -26,6 +26,7 @@
2626
#include <drm/drm_drv.h>
2727
#include <drm/drm_fb_cma_helper.h>
2828
#include <drm/drm_fb_helper.h>
29+
#include <drm/drm_fourcc.h>
2930
#include <drm/drm_gem_cma_helper.h>
3031
#include <drm/drm_gem_framebuffer_helper.h>
3132
#include <drm/drm_irq.h>
@@ -92,8 +93,26 @@ void mxsfb_disable_axi_clk(struct mxsfb_drm_private *mxsfb)
9293
clk_disable_unprepare(mxsfb->clk_axi);
9394
}
9495

96+
static struct drm_framebuffer *
97+
mxsfb_fb_create(struct drm_device *dev, struct drm_file *file_priv,
98+
const struct drm_mode_fb_cmd2 *mode_cmd)
99+
{
100+
const struct drm_format_info *info;
101+
102+
info = drm_get_format_info(dev, mode_cmd);
103+
if (!info)
104+
return ERR_PTR(-EINVAL);
105+
106+
if (mode_cmd->width * info->cpp[0] != mode_cmd->pitches[0]) {
107+
dev_dbg(dev->dev, "Invalid pitch: fb width must match pitch\n");
108+
return ERR_PTR(-EINVAL);
109+
}
110+
111+
return drm_gem_fb_create(dev, file_priv, mode_cmd);
112+
}
113+
95114
static const struct drm_mode_config_funcs mxsfb_mode_config_funcs = {
96-
.fb_create = drm_gem_fb_create,
115+
.fb_create = mxsfb_fb_create,
97116
.atomic_check = drm_atomic_helper_check,
98117
.atomic_commit = drm_atomic_helper_commit,
99118
};

0 commit comments

Comments
 (0)