From patchwork Wed Apr 9 08:45:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 14044358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D108DC369A1 for ; Wed, 9 Apr 2025 08:50:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2B2EC10E782; Wed, 9 Apr 2025 08:50:35 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 111DF10E80E for ; Wed, 9 Apr 2025 08:50:34 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 86FCC1F38A; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 650E813A7A; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AMZPF8w09mdgZQAAD6G6ig (envelope-from ); Wed, 09 Apr 2025 08:50:20 +0000 From: Thomas Zimmermann To: javierm@redhat.com Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 1/3] drm/sysfb: Split source file Date: Wed, 9 Apr 2025 10:45:36 +0200 Message-ID: <20250409084729.236719-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250409084729.236719-1-tzimmermann@suse.de> References: <20250409084729.236719-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Rspamd-Queue-Id: 86FCC1F38A X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Split drm_sysfb_helper.c into two source files. There's no one source file for the mode-setting pipeline and one source file for module meta data. Prepares for adding additional source code to sysfb helpers. Signed-off-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/sysfb/Makefile | 3 +++ drivers/gpu/drm/sysfb/drm_sysfb.c | 8 ++++++++ drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 5 +++++ .../drm/sysfb/{drm_sysfb_helper.c => drm_sysfb_modeset.c} | 4 ---- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb.c rename drivers/gpu/drm/sysfb/{drm_sysfb_helper.c => drm_sysfb_modeset.c} (98%) diff --git a/drivers/gpu/drm/sysfb/Makefile b/drivers/gpu/drm/sysfb/Makefile index 0d2518c971634..861b4026f4a6e 100644 --- a/drivers/gpu/drm/sysfb/Makefile +++ b/drivers/gpu/drm/sysfb/Makefile @@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only +drm_sysfb_helper-y := \ + drm_sysfb.o \ + drm_sysfb_modeset.o obj-$(CONFIG_DRM_SYSFB_HELPER) += drm_sysfb_helper.o obj-$(CONFIG_DRM_EFIDRM) += efidrm.o diff --git a/drivers/gpu/drm/sysfb/drm_sysfb.c b/drivers/gpu/drm/sysfb/drm_sysfb.c new file mode 100644 index 0000000000000..c083d21fd9cab --- /dev/null +++ b/drivers/gpu/drm/sysfb/drm_sysfb.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +#include "drm_sysfb_helper.h" + +MODULE_DESCRIPTION("Helpers for DRM sysfb drivers"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h index 3684bd0ef0853..ee94d6199b601 100644 --- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h +++ b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h @@ -11,6 +11,11 @@ #include struct drm_format_info; +struct drm_scanout_buffer; + +/* + * Display modes + */ struct drm_display_mode drm_sysfb_mode(unsigned int width, unsigned int height, diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.c b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c similarity index 98% rename from drivers/gpu/drm/sysfb/drm_sysfb_helper.c rename to drivers/gpu/drm/sysfb/drm_sysfb_modeset.c index 262490a717924..ffaa2522ab965 100644 --- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.c +++ b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -20,9 +19,6 @@ #include "drm_sysfb_helper.h" -MODULE_DESCRIPTION("Helpers for DRM sysfb drivers"); -MODULE_LICENSE("GPL"); - struct drm_display_mode drm_sysfb_mode(unsigned int width, unsigned int height, unsigned int width_mm, From patchwork Wed Apr 9 08:45:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 14044357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCEBFC36002 for ; Wed, 9 Apr 2025 08:50:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FC4E10E309; Wed, 9 Apr 2025 08:50:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="zQStIXSP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kkfOIjQq"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="zQStIXSP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kkfOIjQq"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5FCE10E07F for ; Wed, 9 Apr 2025 08:50:25 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AF8F521163; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1744188620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IPQnDVQJTg1ySADHT5ackP7kaVQREJ8hnaYtYMQtzPI=; b=zQStIXSPUiAKnX0gp0lTsDUmYPU4dP6OIBy43vogOnjYaP8Qrg7Agfu6s6Pfnw2ZLfL7uY nT0KozxFa0/1EA1W/iKRrJkb5zq7mCJl+WNG0ghG9Q3nOIYNHNRTKLav3UdudmzaCncVun 7FnkIWjFFJJgLGZPXYsXlw0zJE1Fyso= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1744188620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IPQnDVQJTg1ySADHT5ackP7kaVQREJ8hnaYtYMQtzPI=; b=kkfOIjQq9cQoQ15tW8ZLPgh6SCYobNLnfDpVjriOl68Zk/7bu7vcIEoQbKiELXOwzYKzhT LReImneuDAxGBzBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1744188620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IPQnDVQJTg1ySADHT5ackP7kaVQREJ8hnaYtYMQtzPI=; b=zQStIXSPUiAKnX0gp0lTsDUmYPU4dP6OIBy43vogOnjYaP8Qrg7Agfu6s6Pfnw2ZLfL7uY nT0KozxFa0/1EA1W/iKRrJkb5zq7mCJl+WNG0ghG9Q3nOIYNHNRTKLav3UdudmzaCncVun 7FnkIWjFFJJgLGZPXYsXlw0zJE1Fyso= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1744188620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IPQnDVQJTg1ySADHT5ackP7kaVQREJ8hnaYtYMQtzPI=; b=kkfOIjQq9cQoQ15tW8ZLPgh6SCYobNLnfDpVjriOl68Zk/7bu7vcIEoQbKiELXOwzYKzhT LReImneuDAxGBzBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8CCD613691; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qHsGIcw09mdgZQAAD6G6ig (envelope-from ); Wed, 09 Apr 2025 08:50:20 +0000 From: Thomas Zimmermann To: javierm@redhat.com Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 2/3] drm/sysfb: Share helpers for integer validation Date: Wed, 9 Apr 2025 10:45:37 +0200 Message-ID: <20250409084729.236719-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250409084729.236719-1-tzimmermann@suse.de> References: <20250409084729.236719-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Provide sysfb helpers for validating framebuffer integer values against limits. Update drivers. If a driver did not specify a limit for a certain value, use INT_MAX. Signed-off-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/sysfb/drm_sysfb.c | 27 ++++++++++++++++++++++ drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 9 ++++++++ drivers/gpu/drm/sysfb/efidrm.c | 29 ++++-------------------- drivers/gpu/drm/sysfb/ofdrm.c | 12 ++-------- drivers/gpu/drm/sysfb/simpledrm.c | 14 ++---------- drivers/gpu/drm/sysfb/vesadrm.c | 29 ++++-------------------- 6 files changed, 48 insertions(+), 72 deletions(-) diff --git a/drivers/gpu/drm/sysfb/drm_sysfb.c b/drivers/gpu/drm/sysfb/drm_sysfb.c index c083d21fd9cab..97547ea5e2131 100644 --- a/drivers/gpu/drm/sysfb/drm_sysfb.c +++ b/drivers/gpu/drm/sysfb/drm_sysfb.c @@ -1,8 +1,35 @@ // SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include #include +#include + #include "drm_sysfb_helper.h" MODULE_DESCRIPTION("Helpers for DRM sysfb drivers"); MODULE_LICENSE("GPL"); + +int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name, + u64 value, u32 max) +{ + if (value > min(max, INT_MAX)) { + drm_warn(dev, "%s of %llu exceeds maximum of %u\n", name, value, max); + return -EINVAL; + } + return value; +} +EXPORT_SYMBOL(drm_sysfb_get_validated_int); + +int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name, + u64 value, u32 max) +{ + if (!value) { + drm_warn(dev, "%s of 0 not allowed\n", name); + return -EINVAL; + } + return drm_sysfb_get_validated_int(dev, name, value, max); +} +EXPORT_SYMBOL(drm_sysfb_get_validated_int0); diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h index ee94d6199b601..1697cf7ace973 100644 --- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h +++ b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h @@ -13,6 +13,15 @@ struct drm_format_info; struct drm_scanout_buffer; +/* + * Input parsing + */ + +int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name, + u64 value, u32 max); +int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name, + u64 value, u32 max); + /* * Display modes */ diff --git a/drivers/gpu/drm/sysfb/efidrm.c b/drivers/gpu/drm/sysfb/efidrm.c index af90064a4c04f..a77ea5285cc1d 100644 --- a/drivers/gpu/drm/sysfb/efidrm.c +++ b/drivers/gpu/drm/sysfb/efidrm.c @@ -33,28 +33,6 @@ #define DRIVER_MAJOR 1 #define DRIVER_MINOR 0 -static int efidrm_get_validated_int(struct drm_device *dev, const char *name, - u64 value, u32 max) -{ - if (max > INT_MAX) - max = INT_MAX; - if (value > max) { - drm_err(dev, "%s of %llu exceeds maximum of %u\n", name, value, max); - return -EINVAL; - } - return value; -} - -static int efidrm_get_validated_int0(struct drm_device *dev, const char *name, - u64 value, u32 max) -{ - if (!value) { - drm_err(dev, "%s of 0 not allowed\n", name); - return -EINVAL; - } - return efidrm_get_validated_int(dev, name, value, max); -} - static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name, u64 value, u64 max) { @@ -70,12 +48,12 @@ static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name, static int efidrm_get_width_si(struct drm_device *dev, const struct screen_info *si) { - return efidrm_get_validated_int0(dev, "width", si->lfb_width, U16_MAX); + return drm_sysfb_get_validated_int0(dev, "width", si->lfb_width, U16_MAX); } static int efidrm_get_height_si(struct drm_device *dev, const struct screen_info *si) { - return efidrm_get_validated_int0(dev, "height", si->lfb_height, U16_MAX); + return drm_sysfb_get_validated_int0(dev, "height", si->lfb_height, U16_MAX); } static struct resource *efidrm_get_memory_si(struct drm_device *dev, @@ -102,7 +80,8 @@ static int efidrm_get_stride_si(struct drm_device *dev, const struct screen_info if (!lfb_linelength) lfb_linelength = drm_format_info_min_pitch(format, 0, width); - return efidrm_get_validated_int0(dev, "stride", lfb_linelength, div64_u64(size, height)); + return drm_sysfb_get_validated_int0(dev, "stride", lfb_linelength, + div64_u64(size, height)); } static u64 efidrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si, diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c index 86c1a0c80ceb3..fddfe8bea9f7f 100644 --- a/drivers/gpu/drm/sysfb/ofdrm.c +++ b/drivers/gpu/drm/sysfb/ofdrm.c @@ -78,20 +78,12 @@ enum ofdrm_model { static int display_get_validated_int(struct drm_device *dev, const char *name, uint32_t value) { - if (value > INT_MAX) { - drm_err(dev, "invalid framebuffer %s of %u\n", name, value); - return -EINVAL; - } - return (int)value; + return drm_sysfb_get_validated_int(dev, name, value, INT_MAX); } static int display_get_validated_int0(struct drm_device *dev, const char *name, uint32_t value) { - if (!value) { - drm_err(dev, "invalid framebuffer %s of %u\n", name, value); - return -EINVAL; - } - return display_get_validated_int(dev, name, value); + return drm_sysfb_get_validated_int0(dev, name, value, INT_MAX); } static const struct drm_format_info *display_get_validated_format(struct drm_device *dev, diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c index f37b1994de71f..a1c3119330def 100644 --- a/drivers/gpu/drm/sysfb/simpledrm.c +++ b/drivers/gpu/drm/sysfb/simpledrm.c @@ -42,24 +42,14 @@ static int simplefb_get_validated_int(struct drm_device *dev, const char *name, uint32_t value) { - if (value > INT_MAX) { - drm_err(dev, "simplefb: invalid framebuffer %s of %u\n", - name, value); - return -EINVAL; - } - return (int)value; + return drm_sysfb_get_validated_int(dev, name, value, INT_MAX); } static int simplefb_get_validated_int0(struct drm_device *dev, const char *name, uint32_t value) { - if (!value) { - drm_err(dev, "simplefb: invalid framebuffer %s of %u\n", - name, value); - return -EINVAL; - } - return simplefb_get_validated_int(dev, name, value); + return drm_sysfb_get_validated_int0(dev, name, value, INT_MAX); } static const struct drm_format_info * diff --git a/drivers/gpu/drm/sysfb/vesadrm.c b/drivers/gpu/drm/sysfb/vesadrm.c index 9cc50e3072ead..d87ff77be20de 100644 --- a/drivers/gpu/drm/sysfb/vesadrm.c +++ b/drivers/gpu/drm/sysfb/vesadrm.c @@ -36,28 +36,6 @@ #define VESADRM_GAMMA_LUT_SIZE 256 -static int vesadrm_get_validated_int(struct drm_device *dev, const char *name, - u64 value, u32 max) -{ - if (max > INT_MAX) - max = INT_MAX; - if (value > max) { - drm_err(dev, "%s of %llu exceeds maximum of %u\n", name, value, max); - return -EINVAL; - } - return value; -} - -static int vesadrm_get_validated_int0(struct drm_device *dev, const char *name, - u64 value, u32 max) -{ - if (!value) { - drm_err(dev, "%s of 0 not allowed\n", name); - return -EINVAL; - } - return vesadrm_get_validated_int(dev, name, value, max); -} - static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name, u64 value, u64 max) { @@ -73,12 +51,12 @@ static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name, static int vesadrm_get_width_si(struct drm_device *dev, const struct screen_info *si) { - return vesadrm_get_validated_int0(dev, "width", si->lfb_width, U16_MAX); + return drm_sysfb_get_validated_int0(dev, "width", si->lfb_width, U16_MAX); } static int vesadrm_get_height_si(struct drm_device *dev, const struct screen_info *si) { - return vesadrm_get_validated_int0(dev, "height", si->lfb_height, U16_MAX); + return drm_sysfb_get_validated_int0(dev, "height", si->lfb_height, U16_MAX); } static struct resource *vesadrm_get_memory_si(struct drm_device *dev, @@ -105,7 +83,8 @@ static int vesadrm_get_stride_si(struct drm_device *dev, const struct screen_inf if (!lfb_linelength) lfb_linelength = drm_format_info_min_pitch(format, 0, width); - return vesadrm_get_validated_int0(dev, "stride", lfb_linelength, div64_u64(size, height)); + return drm_sysfb_get_validated_int0(dev, "stride", lfb_linelength, + div64_u64(size, height)); } static u64 vesadrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si, From patchwork Wed Apr 9 08:45:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 14044359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3BB30C36002 for ; Wed, 9 Apr 2025 08:50:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8601610E80E; Wed, 9 Apr 2025 08:50:37 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 28B5410E782 for ; Wed, 9 Apr 2025 08:50:34 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E158221168; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B5A0D13A7A; Wed, 9 Apr 2025 08:50:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6EoBK8w09mdgZQAAD6G6ig (envelope-from ); Wed, 09 Apr 2025 08:50:20 +0000 From: Thomas Zimmermann To: javierm@redhat.com Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 3/3] drm/sysfb: Share helpers for screen_info validation Date: Wed, 9 Apr 2025 10:45:38 +0200 Message-ID: <20250409084729.236719-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250409084729.236719-1-tzimmermann@suse.de> References: <20250409084729.236719-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Rspamd-Queue-Id: E158221168 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Share efidrm's and vesadrm's validation of struct screen_info in shared helpers. Update the drivers. Most validation helpers test individual values against limits and can be shared as they are. For color formats, a common helper looks up the correct DRM format info from a driver-provided list of color formats. These screen_info helpers are only available if CONFIG_SCREEN_INFO has been selected, as done by efidrm and vesadrm. Signed-off-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/sysfb/Makefile | 1 + drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 34 ++++++ drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c | 107 ++++++++++++++++++ drivers/gpu/drm/sysfb/efidrm.c | 105 ++--------------- drivers/gpu/drm/sysfb/vesadrm.c | 105 ++--------------- 5 files changed, 160 insertions(+), 192 deletions(-) create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c diff --git a/drivers/gpu/drm/sysfb/Makefile b/drivers/gpu/drm/sysfb/Makefile index 861b4026f4a6e..a156c496413d3 100644 --- a/drivers/gpu/drm/sysfb/Makefile +++ b/drivers/gpu/drm/sysfb/Makefile @@ -3,6 +3,7 @@ drm_sysfb_helper-y := \ drm_sysfb.o \ drm_sysfb_modeset.o +drm_sysfb_helper-$(CONFIG_SCREEN_INFO) += drm_sysfb_screen_info.o obj-$(CONFIG_DRM_SYSFB_HELPER) += drm_sysfb_helper.o obj-$(CONFIG_DRM_EFIDRM) += efidrm.o diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h index 1697cf7ace973..cb08a88242cc1 100644 --- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h +++ b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h @@ -6,12 +6,46 @@ #include #include +#include