Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4063813pxk; Tue, 8 Sep 2020 09:45:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWyfPna1lbXJAc1tb+VevGbqFFBE6+YU9ZM2ZddywVG40FCaFeOozhC6RoFUq4dX1ItaTK X-Received: by 2002:a17:906:e216:: with SMTP id gf22mr18432740ejb.2.1599583499875; Tue, 08 Sep 2020 09:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599583499; cv=none; d=google.com; s=arc-20160816; b=HY7HaDV3dm45DfXPXNHlfgFg7HNeyR2vqDqqe5KmTPyWylezjsU0IvtoK7NLT6oL+g eIutuVCP8A/xdx3pTNKWSzMurrl3xNcy4VcPIHA4AcXeYm7wXW33/ZGtYw5UbSYzPhsn T76/yC2jqnpVRWObekvOV6z5qKYL4bQz1tJDgXpq0XOQWNTOE81YWEKU68W8l7YH4HRQ 5S2rNSnCPT5g3NJ+HhyMhv1zt7oNYoLWSBp81+xCZ0qhKHcREJtLS5jjb9n4kmdmTKvT xu3Dv7AmxEJQJ1Q6p+BgGn8rFHK13nCUChDnpjSg8w3XY9ZjwgDV/1QFzZiuwe0ElJIr weWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qxfcotVSiPgSlKPB5rZ5xXDXpnK6trtv7RzFevjZqVc=; b=EJUhODskiNbl/kzsu/9tY6c+fxfmnw6z3bOrPVU9EUwOzCVgIaD58ukNLO+1tDmC3P xfkLjv4KuZxpLE7ekEMtJ+QDgmYQkHrWCTTZwjIovWTrgLxnD/RVKyhZHsGEeVbpSNjy b7riz3SugHHD7v5F3HJZ6g1axN8jJs0dJ8w1N+KVulMZHQkGS9W5Bbd/0BSrmZx7xfeR xehdlv4akUf50ymXUA/rpAc3B2vaUEe3ngFG7tN5foC/aFimqqOtjDdDpNJ7I3h117cb cmmW0H3lC8zQYbYCRDjUuwTarony2bTAL+R9H6jh1iw03l7B64sOuRKjnzD2zildlmta Ayow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=GpnxllrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si13446804ejy.84.2020.09.08.09.44.37; Tue, 08 Sep 2020 09:44:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=GpnxllrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732115AbgIHQlh (ORCPT + 99 others); Tue, 8 Sep 2020 12:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732032AbgIHQhO (ORCPT ); Tue, 8 Sep 2020 12:37:14 -0400 Received: from mail.kmu-office.ch (mail.kmu-office.ch [IPv6:2a02:418:6a02::a2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90B99C0612F1 for ; Tue, 8 Sep 2020 05:56:02 -0700 (PDT) Received: from trochilidae.toradex.int (31-10-206-124.static.upc.ch [31.10.206.124]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 6BFD55C4CAB; Tue, 8 Sep 2020 14:56:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1599569760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=qxfcotVSiPgSlKPB5rZ5xXDXpnK6trtv7RzFevjZqVc=; b=GpnxllrNBTG+jCZMxIjRiuwMkKDhmunZ5oYrsTtVr2FjWZ8FBeSR3aOGSCi7oxp+4zOEZD YK2pCIkK0Kx+ZXHdzzFoKzQv6R7cIYiuV7+Ho/qw0lMc2tEpjklLwNUcVrnZ/1kNm0HRUQ XuSQkc1BYcXovM4hqzcwycbL+krdrP0= From: Stefan Agner To: marex@denx.de, stefan@agner.ch Cc: laurent.pinchart@ideasonboard.com, airlied@linux.ie, daniel@ffwll.ch, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, tomi.valkeinen@ti.com, linux-imx@nxp.com, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm: mxsfb: check framebuffer pitch Date: Tue, 8 Sep 2020 14:55:58 +0200 Message-Id: <20200908125558.256843-1-stefan@agner.ch> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 tires 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. Signed-off-by: Stefan Agner --- drivers/gpu/drm/mxsfb/mxsfb_drv.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c index 8c549c3931af..fa6798d21029 100644 --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -81,8 +82,26 @@ void mxsfb_disable_axi_clk(struct mxsfb_drm_private *mxsfb) clk_disable_unprepare(mxsfb->clk_axi); } +static struct drm_framebuffer * +mxsfb_fb_create(struct drm_device *dev, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + const struct drm_format_info *info; + + info = drm_get_format_info(dev, mode_cmd); + if (!info) + return ERR_PTR(-EINVAL); + + if (mode_cmd->width * info->cpp[0] != mode_cmd->pitches[0]) { + dev_dbg(dev->dev, "Invalid pitch: fb width must match pitch\n"); + return ERR_PTR(-EINVAL); + } + + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + static const struct drm_mode_config_funcs mxsfb_mode_config_funcs = { - .fb_create = drm_gem_fb_create, + .fb_create = mxsfb_fb_create, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, }; -- 2.28.0