Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14174969ybl; Mon, 30 Dec 2019 05:28:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxPzEzdgXlC72bSK3YvvK/6ixZjMLK1Zu2k7nhVxSG8n6vhSTHd/iwRBUBdEKUr/hahplki X-Received: by 2002:a9d:6d8f:: with SMTP id x15mr66107686otp.322.1577712521714; Mon, 30 Dec 2019 05:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577712521; cv=none; d=google.com; s=arc-20160816; b=HaXfX7clkR1+bB0HP94WZ4muF1gdYWEPiYiPMo4VmczXgF7OUFBFymTyacJGWNWyLy Ht84IAykidagZyy5KFzFdWHxayOd1+W2h4fIeybOs3ARvVM5cpf3OSM612AOqhwdI+wD xsjX1qNCj+deJyCvDrH8yxe9F/t/R4vhUhy9r1Fl/XzlwqEmLX4uRl7xxEF9HErc0aNT oo0Bv8Z7inWofhpkN4cCMGVRwPdJ7aq/laUOcUv+hzjG1MX5RO+pHO1U2fNLhjN1cum0 uyGZM/4Ls/73UhUgycyE7yvN+QMpSjCIZ7X9ClIMAP6mi9wWuxrUStKkag+4BA1tGTF6 /zKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=EqiGa/GxzwOTS/nIZqkO7ddjalnXRSi2DzvsHkNvqO4=; b=NpxF68eEZxgTGzx/KWNBwNOLeVVL7eO7X4Z2PLHrQA/hV8C+/naNs7QROBYdSoNZRo qWyvSx838/PczlanCtCXBoLR8ZVFfqbfQybmx4R3ZFD77WXK37o64MFXpPyzDUZ79Mxj w7ljJ+5cynXfpNUo7oYqFRwpXEoTk0rvwF4AwH9NLKZgAmJSETaXT1tg3cQu6Mjn0xcO XQ8lAU2zsosbqroIRVi488G8WJ+EtZ1NTfnQVZbjJTIh9uc85IUECl1w9t0MYE352ynU tV5he+zWoiEu2rMO7pvbZr3bGNHR1i2Jh/DB0mj6yDeUUM6WiZkPGe8P5pIZ7O3Lu54d givw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6si22828031otq.95.2019.12.30.05.28.29; Mon, 30 Dec 2019 05:28:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727473AbfL3N1p (ORCPT + 99 others); Mon, 30 Dec 2019 08:27:45 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:49052 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727454AbfL3N1p (ORCPT ); Mon, 30 Dec 2019 08:27:45 -0500 Received: from ramsan ([84.195.182.253]) by andre.telenet-ops.be with bizsmtp id kDTf2100A5USYZQ01DTf3m; Mon, 30 Dec 2019 14:27:42 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1ilv59-0001Yv-B0; Mon, 30 Dec 2019 14:27:39 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1ilv59-0001C0-8p; Mon, 30 Dec 2019 14:27:39 +0100 From: Geert Uytterhoeven To: Stefan Agner , Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , Bartlomiej Zolnierkiewicz Cc: Tomi Valkeinen , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] drm/fb-helper: Round up bits_per_pixel if possible Date: Mon, 30 Dec 2019 14:27:34 +0100 Message-Id: <20191230132734.4538-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When userspace requests a video mode parameter value that is not supported, frame buffer device drivers should round it up to a supported value, if possible, instead of just rejecting it. This allows applications to quickly scan for supported video modes. Currently this rule is not followed for the number of bits per pixel, causing e.g. "fbset -depth N" to fail, if N is smaller than the current number of bits per pixel. Fix this by returning an error only if bits per pixel is too large, and setting it to the current value otherwise. See also Documentation/fb/framebuffer.rst, Section 2 (Programmer's View of /dev/fb*"). Fixes: 865afb11949e5bf4 ("drm/fb-helper: reject any changes to the fbdev") Signed-off-by: Geert Uytterhoeven --- Against drm-misc#for-linux-next. Applies with some fuzz against v5.5-rc4. --- drivers/gpu/drm/drm_fb_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index f8e9051926083373..cae8fa74781c8db0 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1267,7 +1267,7 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var, * Changes struct fb_var_screeninfo are currently not pushed back * to KMS, hence fail if different settings are requested. */ - if (var->bits_per_pixel != fb->format->cpp[0] * 8 || + if (var->bits_per_pixel > fb->format->cpp[0] * 8 || var->xres > fb->width || var->yres > fb->height || var->xres_virtual > fb->width || var->yres_virtual > fb->height) { drm_dbg_kms(dev, "fb requested width/height/bpp can't fit in current fb " @@ -1292,6 +1292,11 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var, drm_fb_helper_fill_pixel_fmt(var, fb->format->depth); } + /* + * Likewise, bits_per_pixel should be rounded up to a supported value. + */ + var->bits_per_pixel = fb->format->cpp[0] * 8; + /* * drm fbdev emulation doesn't support changing the pixel format at all, * so reject all pixel format changing requests. -- 2.17.1