From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B79683E6388 for ; Fri, 27 Mar 2026 13:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616679; cv=none; b=PJQiW9MvimirR6LLBTMceJV336N3S8F4leXyC+VsGTDeKZZZK3yfbixsVYZzCw1+R6rwK9wZJm2ZCxXZR2O7Qvz9PFt4k0MAzr47xytjP9rSK8FObY7o0P78QkvtCdQejh6UNvHFnM0g/jgVhJOiIN2UU1NrQMHP6ja4bQ+Ns6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616679; c=relaxed/simple; bh=0Enk6zN0+6/OhBFfGHJz9coCUsGMV5UM92PLDdpD/uM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iziKy7tq9t5fwsBGUMXGMecLutLW3Av8IDf+BBzDMlaSAwwObMKHFoP/RNniaMPR1Ps+Hrp2ZS+m/xKlAJxMO1WDVNMoAfVExw5AN6RosSV+KEOPkBMD+2cJqo1YQFuqk5Qejqglp+GKMStbi7oIH6Q2oXDaHojUgjdRKXNyoxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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 386774D31C; Fri, 27 Mar 2026 13:04:36 +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 E425B4A0B1; Fri, 27 Mar 2026 13:04:35 +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 uK6ANmOAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:35 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann , stable@vger.kernel.org Subject: [PATCH 01/10] fbcon: Avoid OOB font access if console rotation fails Date: Fri, 27 Mar 2026 13:49:34 +0100 Message-ID: <20260327130431.59481-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 386774D31C X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Score: -4.00 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Content-Type: text/plain; charset="utf-8" Clear the font buffer if the reallocation during console rotation fails in fbcon_rotate_font(). The putcs implementations for the rotated buffer will return early in this case. See [1] for an example. Currently, fbcon_rotate_font() keeps the old buffer, which is to small for the rotated font. Printing to the rotated console with a high-enough character code will overflow the font buffer. Signed-off-by: Thomas Zimmermann Fixes: 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rota= te font bitmap") Cc: # v2.6.15+ Link: https://elixir.bootlin.com/linux/v6.19/source/drivers/video/fbdev/cor= e/fbcon_ccw.c#L144 # [1] --- drivers/video/fbdev/core/fbcon_rotate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/= core/fbcon_rotate.c index 1562a8f20b4f..5348f6c6f57c 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -46,6 +46,10 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_da= ta *vc) info->fbops->fb_sync(info); =20 if (par->fd_size < d_cellsize * len) { + kfree(par->fontbuffer); + par->fontbuffer =3D NULL; + par->fd_size =3D 0; + dst =3D kmalloc_array(len, d_cellsize, GFP_KERNEL); =20 if (dst =3D=3D NULL) { @@ -54,7 +58,6 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_dat= a *vc) } =20 par->fd_size =3D d_cellsize * len; - kfree(par->fontbuffer); par->fontbuffer =3D dst; } =20 --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9276A3E6DD0 for ; Fri, 27 Mar 2026 13:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616686; cv=none; b=uB4CQXqJXS5Ypn5Fdd7hXR+yxM+9QoKL8nOVXF0ZSViiZ7AYZyUcAwtzUTs1XnMGHdb/hRpfKfH5vGFqp6/Gr/02l4ZwAJ3nFXi3UoBfdhqJyKZlQo0UqJW2XUT+B747QPutkvStpXZTf2dCLeyTN2CXe4Jod4b46Qknvk31uZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616686; c=relaxed/simple; bh=7SWK6+xforbO9ObuX1tAwg0BTEZ2KvUbTuIZ961ycCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GwylmNAO6OMuuXB0AbJjLHT0efpjRMbWzf9sMg7Ema8WjBg+IHwJD9NM5fvxmrKpFaqRLPWul5cv0QdLBT+g9sybZeGvamQub79iLOwpXLQ9hDw5Klh+A28Uj1h/1VPIustuiHUFZThMCfjIFg7pAgfN2937QDAc+HgN9NvGBWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=mdH5OOOS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zTO/JAbr; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=mdH5OOOS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zTO/JAbr; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mdH5OOOS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zTO/JAbr"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mdH5OOOS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zTO/JAbr" 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-out2.suse.de (Postfix) with ESMTPS id 7DE095BE3D; Fri, 27 Mar 2026 13:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616676; 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=76Lu2FhyqR0U2rrMx7Vy0WuE3C2Dk7OvXdlLMk2AL6M=; b=mdH5OOOSREPZ1IUJSb0PHSMI6D07zcchroWeh1RULvFETSTOy8Zctx0EPhSYK0LUgrXiKU aEWJ6MkUygguz6UWy88RpArUJTBHRqefM2wDG9ateaZ8rbByYX9u4IKHQiIlSRPr4S6QkE Kcg7aExVoZAfmXGv6+RKD+zQsVy4u4g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616676; 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=76Lu2FhyqR0U2rrMx7Vy0WuE3C2Dk7OvXdlLMk2AL6M=; b=zTO/JAbrljkCciSwQQrq2EvPiiq7b8Q29FLA+coRxxeOGmGo6IWdyC0w42VvV7S3eIsoGd Ha9p/a5XAuJjN8AA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616676; 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=76Lu2FhyqR0U2rrMx7Vy0WuE3C2Dk7OvXdlLMk2AL6M=; b=mdH5OOOSREPZ1IUJSb0PHSMI6D07zcchroWeh1RULvFETSTOy8Zctx0EPhSYK0LUgrXiKU aEWJ6MkUygguz6UWy88RpArUJTBHRqefM2wDG9ateaZ8rbByYX9u4IKHQiIlSRPr4S6QkE Kcg7aExVoZAfmXGv6+RKD+zQsVy4u4g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616676; 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=76Lu2FhyqR0U2rrMx7Vy0WuE3C2Dk7OvXdlLMk2AL6M=; b=zTO/JAbrljkCciSwQQrq2EvPiiq7b8Q29FLA+coRxxeOGmGo6IWdyC0w42VvV7S3eIsoGd Ha9p/a5XAuJjN8AA== 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 3E1D64A0A2; Fri, 27 Mar 2026 13:04:36 +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 0Dn3DWSAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:36 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 02/10] vt: Implement helpers for struct vc_font in source file Date: Fri, 27 Mar 2026 13:49:35 +0100 Message-ID: <20260327130431.59481-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_TO(0.00)[gmx.de,linuxfoundation.org,kernel.org,ffwll.ch,ravnborg.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[10]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmx.de] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Move the helpers vc_font_pitch() and vc_font_size() from the VT header file into source file. They are not called very often, so there's no benefit in keeping them in the headers. Also avoids including from the header. Signed-off-by: Thomas Zimmermann Acked-by: Greg Kroah-Hartman --- drivers/tty/vt/vt.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/console_struct.h | 30 ++--------------------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index e2df99e3d458..3d89d30c9596 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -71,6 +71,7 @@ * by Adam Tla/lka , Aug 2006 */ =20 +#include #include #include #include @@ -230,6 +231,40 @@ enum { blank_vesa_wait, }; =20 +/* + * struct vc_font + */ + +/** + * vc_font_pitch - Calculates the number of bytes between two adjacent sca= nlines + * @font: The VC font + * + * Returns: + * The number of bytes between two adjacent scanlines in the font data + */ +unsigned int vc_font_pitch(const struct vc_font *font) +{ + return DIV_ROUND_UP(font->width, 8); +} +EXPORT_SYMBOL_GPL(vc_font_pitch); + +/** + * vc_font_size - Calculates the size of the font data in bytes + * @font: The VC font + * + * vc_font_size() calculates the number of bytes of font data in the + * font specified by @font. The function calculates the size from the + * font parameters. + * + * Returns: + * The size of the font data in bytes. + */ +unsigned int vc_font_size(const struct vc_font *font) +{ + return font->height * vc_font_pitch(font) * font->charcount; +} +EXPORT_SYMBOL_GPL(vc_font_size); + /* * /sys/class/tty/tty0/ * diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h index 6ce498b31855..fe915afdece5 100644 --- a/include/linux/console_struct.h +++ b/include/linux/console_struct.h @@ -13,7 +13,6 @@ #ifndef _LINUX_CONSOLE_STRUCT_H #define _LINUX_CONSOLE_STRUCT_H =20 -#include #include #include #include @@ -83,33 +82,8 @@ struct vc_font { const unsigned char *data; }; =20 -/** - * vc_font_pitch - Calculates the number of bytes between two adjacent sca= nlines - * @font: The VC font - * - * Returns: - * The number of bytes between two adjacent scanlines in the font data - */ -static inline unsigned int vc_font_pitch(const struct vc_font *font) -{ - return DIV_ROUND_UP(font->width, 8); -} - -/** - * vc_font_size - Calculates the size of the font data in bytes - * @font: The VC font - * - * vc_font_size() calculates the number of bytes of font data in the - * font specified by @font. The function calculates the size from the - * font parameters. - * - * Returns: - * The size of the font data in bytes. - */ -static inline unsigned int vc_font_size(const struct vc_font *font) -{ - return font->height * vc_font_pitch(font) * font->charcount; -} +unsigned int vc_font_pitch(const struct vc_font *font); +unsigned int vc_font_size(const struct vc_font *font); =20 /* * Example: vc_data of a console that was scrolled 3 lines down. --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A8033E9296 for ; Fri, 27 Mar 2026 13:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616686; cv=none; b=Cl4H5OPuRcZHQVwBEnw/HQFggf7c1PZKOEiF18Mz6aJPAyhimxdUcWGq2NcoQLZJCmPgelQeZTODnCzVHHWbwsjbDjtPFENBaXAVpLyWrAFrG1Bx7mJTXTTLIiuO3VFmkb7YARcaD2zVfMcbzoq2aIms7ohViC07oiW3jMUu0Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616686; c=relaxed/simple; bh=bEeVkLLDZ7r9bPa02ZXAwIpFbTAvlYuoLbgETZyDsxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tW8bXTjf79ltOOwwsXBMXEMUI67TAeRbB333V/tSv9DDzC/hvM4tNRrdaY1NnS8QoyRTslUOg2RUXKeWwcxG7kzegFcu+5eN2trMJ//ZaIyLcURa9T5Whafza6nDIWpBiIqySsVMbx541Z/f7qkMSH05WFPvzWS69Xw2GkBFww8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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 C6A1B4D34D; Fri, 27 Mar 2026 13:04:36 +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 8661F4A0B1; Fri, 27 Mar 2026 13:04:36 +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 cOSGH2SAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:36 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 03/10] lib/fonts: Provide helpers for calculating glyph pitch and size Date: Fri, 27 Mar 2026 13:49:36 +0100 Message-ID: <20260327130431.59481-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: C6A1B4D34D X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Score: -4.00 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Content-Type: text/plain; charset="utf-8" Implement pitch and size calculation for a single font glyph in the new helpers font_glyph_pitch() and font_glyph_size(). Replace the instances where the calculations are opencoded. Note that in the case of fbcon console rotation, the parameters for a glyph's width and height might be reversed. This is intentionally. Signed-off-by: Thomas Zimmermann --- drivers/tty/vt/vt.c | 5 ++-- drivers/video/fbdev/core/fbcon_ccw.c | 11 +++---- drivers/video/fbdev/core/fbcon_cw.c | 11 +++---- drivers/video/fbdev/core/fbcon_rotate.c | 6 ++-- drivers/video/fbdev/core/fbcon_ud.c | 7 +++-- include/linux/font.h | 40 +++++++++++++++++++++++++ lib/fonts/fonts.c | 2 +- 7 files changed, 61 insertions(+), 21 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 3d89d30c9596..23b9683b52a5 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -71,7 +71,6 @@ * by Adam Tla/lka , Aug 2006 */ =20 -#include #include #include #include @@ -244,7 +243,7 @@ enum { */ unsigned int vc_font_pitch(const struct vc_font *font) { - return DIV_ROUND_UP(font->width, 8); + return font_glyph_pitch(font->width); } EXPORT_SYMBOL_GPL(vc_font_pitch); =20 @@ -261,7 +260,7 @@ EXPORT_SYMBOL_GPL(vc_font_pitch); */ unsigned int vc_font_size(const struct vc_font *font) { - return font->height * vc_font_pitch(font) * font->charcount; + return font_glyph_size(font->width, font->height) * font->charcount; } EXPORT_SYMBOL_GPL(vc_font_size); =20 diff --git a/drivers/video/fbdev/core/fbcon_ccw.c b/drivers/video/fbdev/cor= e/fbcon_ccw.c index 2f394b5a17f7..96ef449ee6ac 100644 --- a/drivers/video/fbdev/core/fbcon_ccw.c +++ b/drivers/video/fbdev/core/fbcon_ccw.c @@ -26,7 +26,7 @@ static void ccw_update_attr(u8 *dst, u8 *src, int attribu= te, struct vc_data *vc) { int i, j, offset =3D (vc->vc_font.height < 10) ? 1 : 2; - int width =3D (vc->vc_font.height + 7) >> 3; + int width =3D font_glyph_pitch(vc->vc_font.height); int mod =3D vc->vc_font.height % 8; u8 c, msk =3D ~(0xff << offset), msk1 =3D 0; =20 @@ -101,7 +101,7 @@ static inline void ccw_putcs_aligned(struct vc_data *vc= , struct fb_info *info, { struct fbcon_par *par =3D info->fbcon_par; u16 charmask =3D vc->vc_hi_font_mask ? 0x1ff : 0xff; - u32 idx =3D (vc->vc_font.height + 7) >> 3; + u32 idx =3D font_glyph_pitch(vc->vc_font.height); u8 *src; =20 while (cnt--) { @@ -131,7 +131,7 @@ static void ccw_putcs(struct vc_data *vc, struct fb_inf= o *info, { struct fb_image image; struct fbcon_par *par =3D info->fbcon_par; - u32 width =3D (vc->vc_font.height + 7)/8; + u32 width =3D font_glyph_pitch(vc->vc_font.height); u32 cellsize =3D width * vc->vc_font.width; u32 maxcnt =3D info->pixmap.size/cellsize; u32 scan_align =3D info->pixmap.scan_align - 1; @@ -223,7 +223,8 @@ static void ccw_cursor(struct vc_data *vc, struct fb_in= fo *info, bool enable, struct fb_cursor cursor; struct fbcon_par *par =3D info->fbcon_par; unsigned short charmask =3D vc->vc_hi_font_mask ? 0x1ff : 0xff; - int w =3D (vc->vc_font.height + 7) >> 3, c; + int w =3D font_glyph_pitch(vc->vc_font.height); + int c; int y =3D real_y(par->p, vc->state.y); int attribute, use_sw =3D vc->vc_cursor_type & CUR_SW; int err =3D 1, dx, dy; @@ -297,7 +298,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_in= fo *info, bool enable, char *tmp, *mask =3D kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC); int cur_height, size, i =3D 0; - int width =3D (vc->vc_font.width + 7)/8; + int width =3D font_glyph_pitch(vc->vc_font.width); =20 if (!mask) return; diff --git a/drivers/video/fbdev/core/fbcon_cw.c b/drivers/video/fbdev/core= /fbcon_cw.c index 3c3ad3471ec4..ea712654edae 100644 --- a/drivers/video/fbdev/core/fbcon_cw.c +++ b/drivers/video/fbdev/core/fbcon_cw.c @@ -26,7 +26,7 @@ static void cw_update_attr(u8 *dst, u8 *src, int attribut= e, struct vc_data *vc) { int i, j, offset =3D (vc->vc_font.height < 10) ? 1 : 2; - int width =3D (vc->vc_font.height + 7) >> 3; + int width =3D font_glyph_pitch(vc->vc_font.height); u8 c, msk =3D ~(0xff >> offset); =20 for (i =3D 0; i < vc->vc_font.width; i++) { @@ -86,7 +86,7 @@ static inline void cw_putcs_aligned(struct vc_data *vc, s= truct fb_info *info, { struct fbcon_par *par =3D info->fbcon_par; u16 charmask =3D vc->vc_hi_font_mask ? 0x1ff : 0xff; - u32 idx =3D (vc->vc_font.height + 7) >> 3; + u32 idx =3D font_glyph_pitch(vc->vc_font.height); u8 *src; =20 while (cnt--) { @@ -116,7 +116,7 @@ static void cw_putcs(struct vc_data *vc, struct fb_info= *info, { struct fb_image image; struct fbcon_par *par =3D info->fbcon_par; - u32 width =3D (vc->vc_font.height + 7)/8; + u32 width =3D font_glyph_pitch(vc->vc_font.height); u32 cellsize =3D width * vc->vc_font.width; u32 maxcnt =3D info->pixmap.size/cellsize; u32 scan_align =3D info->pixmap.scan_align - 1; @@ -206,7 +206,8 @@ static void cw_cursor(struct vc_data *vc, struct fb_inf= o *info, bool enable, struct fb_cursor cursor; struct fbcon_par *par =3D info->fbcon_par; unsigned short charmask =3D vc->vc_hi_font_mask ? 0x1ff : 0xff; - int w =3D (vc->vc_font.height + 7) >> 3, c; + int w =3D font_glyph_pitch(vc->vc_font.height); + int c; int y =3D real_y(par->p, vc->state.y); int attribute, use_sw =3D vc->vc_cursor_type & CUR_SW; int err =3D 1, dx, dy; @@ -280,7 +281,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_inf= o *info, bool enable, char *tmp, *mask =3D kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC); int cur_height, size, i =3D 0; - int width =3D (vc->vc_font.width + 7)/8; + int width =3D font_glyph_pitch(vc->vc_font.width); =20 if (!mask) return; diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/= core/fbcon_rotate.c index 5348f6c6f57c..18575c5182db 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -33,14 +33,12 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_d= ata *vc) src =3D par->fontdata =3D vc->vc_font.data; par->cur_rotate =3D par->p->con_rotate; len =3D vc->vc_font.charcount; - s_cellsize =3D ((vc->vc_font.width + 7)/8) * - vc->vc_font.height; + s_cellsize =3D font_glyph_size(vc->vc_font.width, vc->vc_font.height); d_cellsize =3D s_cellsize; =20 if (par->rotate =3D=3D FB_ROTATE_CW || par->rotate =3D=3D FB_ROTATE_CCW) - d_cellsize =3D ((vc->vc_font.height + 7)/8) * - vc->vc_font.width; + d_cellsize =3D font_glyph_size(vc->vc_font.height, vc->vc_font.width); =20 if (info->fbops->fb_sync) info->fbops->fb_sync(info); diff --git a/drivers/video/fbdev/core/fbcon_ud.c b/drivers/video/fbdev/core= /fbcon_ud.c index 6fc30cad5b19..f7cd89c42b01 100644 --- a/drivers/video/fbdev/core/fbcon_ud.c +++ b/drivers/video/fbdev/core/fbcon_ud.c @@ -26,7 +26,7 @@ static void ud_update_attr(u8 *dst, u8 *src, int attribut= e, struct vc_data *vc) { int i, offset =3D (vc->vc_font.height < 10) ? 1 : 2; - int width =3D (vc->vc_font.width + 7) >> 3; + int width =3D font_glyph_pitch(vc->vc_font.width); unsigned int cellsize =3D vc->vc_font.height * width; u8 c; =20 @@ -153,7 +153,7 @@ static void ud_putcs(struct vc_data *vc, struct fb_info= *info, { struct fb_image image; struct fbcon_par *par =3D info->fbcon_par; - u32 width =3D (vc->vc_font.width + 7)/8; + u32 width =3D font_glyph_pitch(vc->vc_font.width); u32 cellsize =3D width * vc->vc_font.height; u32 maxcnt =3D info->pixmap.size/cellsize; u32 scan_align =3D info->pixmap.scan_align - 1; @@ -253,7 +253,8 @@ static void ud_cursor(struct vc_data *vc, struct fb_inf= o *info, bool enable, struct fb_cursor cursor; struct fbcon_par *par =3D info->fbcon_par; unsigned short charmask =3D vc->vc_hi_font_mask ? 0x1ff : 0xff; - int w =3D (vc->vc_font.width + 7) >> 3, c; + int w =3D font_glyph_pitch(vc->vc_font.width); + int c; int y =3D real_y(par->p, vc->state.y); int attribute, use_sw =3D vc->vc_cursor_type & CUR_SW; int err =3D 1, dx, dy; diff --git a/include/linux/font.h b/include/linux/font.h index 5401f07dd6ce..3bd49d914b22 100644 --- a/include/linux/font.h +++ b/include/linux/font.h @@ -11,10 +11,50 @@ #ifndef _VIDEO_FONT_H #define _VIDEO_FONT_H =20 +#include #include =20 struct console_font; =20 +/* + * Glyphs + */ + +/** + * font_glyph_pitch - Calculates the number of bytes per scanline + * @width: The glyph width in bits per scanline + * + * A glyph's pitch is the number of bytes in a single scanline, rounded + * up to the next full byte. The parameter @width receives the number + * of visible bits per scanline. For example, if width is 14 bytes per + * scanline, the pitch is 2 bytes per scanline. If width is 8 bits per + * scanline, the pitch is 1 byte per scanline. + * + * Returns: + * The number of bytes in a single scanline of the glyph + */ +static inline unsigned int font_glyph_pitch(unsigned int width) +{ + return DIV_ROUND_UP(width, 8); +} + +/** + * font_glyph_size - Calculates the number of bytes per glyph + * @width: The glyph width in bits per scanline + * @vpitch: The number of scanlines in the glyph + * + * The number of bytes in a glyph depends on the pitch and the number + * of scanlines. font_glyph_size automatically calculates the pitch + * from the given width. The parameter @vpitch gives the number of + * scanlines, which is usually the glyph's height in scanlines. Fonts + * coming from user space can sometimes have a different vertical pitch + * with empty scanlines between two adjacent glyphs. + */ +static inline unsigned int font_glyph_size(unsigned int width, unsigned in= t vpitch) +{ + return font_glyph_pitch(width) * vpitch; +} + /* * font_data_t and helpers */ diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c index 5938f542906b..f5d5333450a0 100644 --- a/lib/fonts/fonts.c +++ b/lib/fonts/fonts.c @@ -26,7 +26,7 @@ =20 #include "font.h" =20 -#define console_font_pitch(font) DIV_ROUND_UP((font)->width, 8) +#define console_font_pitch(font) font_glyph_pitch((font)->width) =20 /* * Helpers for font_data_t --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EB0E3E8673 for ; Fri, 27 Mar 2026 13:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616694; cv=none; b=LRItWDngtZ3R6Y3PkKF8CUFoRzcMuMaNe3jhmc+pvJ6YxyTtBHJmfTBzXDnaydMzzcb3lkPTeHs8bR8jaBPv6rAIL325gv0I4Z+bK4dyW8H4gaEO6tdWqelKUcx7Wg7IDHOyey5Z2m7S2jWfbacz61c/NT46Ij8/0sFUOfIgy8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616694; c=relaxed/simple; bh=Olc3nRBtwIXKASdckSPHhCbwBLHg8+YGP/umsNIqLxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nRy9UZhmAFDrFSDhsGJBuGN/DRJBBIgeQd9lSMtuqHlCqAUwRQyioslf3tV2h+tXoO8byOUvRI8kqkTH02TppgI6Xyy7YYAoHATALkTN0SSKkAEXGMPTS5TRv+wxDZAvzkdAspfC72tRSF5nMsk7g3Q99r0xV/IZCvL+mK7oMcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Cs3+3U8; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=csVaRRQS; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Cs3+3U8; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=csVaRRQS; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Cs3+3U8"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="csVaRRQS"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Cs3+3U8"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="csVaRRQS" 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 1C8D04D38E; Fri, 27 Mar 2026 13:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616677; 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=3fVGtzGvjoY/rs1Dx30cKvv6gx94IsqDKYHw12bNUsA=; b=0Cs3+3U8x3pLxINPh1x0/3anTyofn2dKKIn55y8+S2jEN89hI0oNIcTo73hvQdWy1m6R9W Pp+qqYbkhxs4QK0zRJ6ivjItkJV7FFaGg4Kgz9obHDANTnceNN12UT2ikUIIFwHAOZ+Uyd lyWXr3Q52yUqC6rNP8aZSWmd+aSqtzg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616677; 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=3fVGtzGvjoY/rs1Dx30cKvv6gx94IsqDKYHw12bNUsA=; b=csVaRRQSKjW6wkRagZWHKOHETOYnvVJvtC/KqKkmOj2JJq9eAjXpM85C+Ixd2tBqRoD8az QGKH1DjrWWIjlhDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616677; 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=3fVGtzGvjoY/rs1Dx30cKvv6gx94IsqDKYHw12bNUsA=; b=0Cs3+3U8x3pLxINPh1x0/3anTyofn2dKKIn55y8+S2jEN89hI0oNIcTo73hvQdWy1m6R9W Pp+qqYbkhxs4QK0zRJ6ivjItkJV7FFaGg4Kgz9obHDANTnceNN12UT2ikUIIFwHAOZ+Uyd lyWXr3Q52yUqC6rNP8aZSWmd+aSqtzg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616677; 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=3fVGtzGvjoY/rs1Dx30cKvv6gx94IsqDKYHw12bNUsA=; b=csVaRRQSKjW6wkRagZWHKOHETOYnvVJvtC/KqKkmOj2JJq9eAjXpM85C+Ixd2tBqRoD8az QGKH1DjrWWIjlhDQ== 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 CDB534A0A2; Fri, 27 Mar 2026 13:04:36 +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 WHgDMWSAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:36 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 04/10] lib/fonts: Clean up Makefile Date: Fri, 27 Mar 2026 13:49:37 +0100 Message-ID: <20260327130431.59481-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; 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]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_TO(0.00)[gmx.de,linuxfoundation.org,kernel.org,ffwll.ch,ravnborg.org]; RCPT_COUNT_SEVEN(0.00)[10]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmx.de] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Simplify the Makefile. Drop font-obj-y and sort the fonts by dictionary order. Done in preparation for supporting optional font rotation. Signed-off-by: Thomas Zimmermann --- lib/fonts/Makefile | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile index 30a85a4292fa..3268d344c0a1 100644 --- a/lib/fonts/Makefile +++ b/lib/fonts/Makefile @@ -1,23 +1,22 @@ # SPDX-License-Identifier: GPL-2.0 # Font handling =20 -font-objs :=3D fonts.o +font-y :=3D fonts.o =20 -font-objs-$(CONFIG_FONT_SUN8x16) +=3D font_sun8x16.o -font-objs-$(CONFIG_FONT_SUN12x22) +=3D font_sun12x22.o -font-objs-$(CONFIG_FONT_8x8) +=3D font_8x8.o -font-objs-$(CONFIG_FONT_8x16) +=3D font_8x16.o -font-objs-$(CONFIG_FONT_6x11) +=3D font_6x11.o -font-objs-$(CONFIG_FONT_7x14) +=3D font_7x14.o -font-objs-$(CONFIG_FONT_10x18) +=3D font_10x18.o -font-objs-$(CONFIG_FONT_PEARL_8x8) +=3D font_pearl_8x8.o -font-objs-$(CONFIG_FONT_ACORN_8x8) +=3D font_acorn_8x8.o -font-objs-$(CONFIG_FONT_MINI_4x6) +=3D font_mini_4x6.o -font-objs-$(CONFIG_FONT_6x10) +=3D font_6x10.o -font-objs-$(CONFIG_FONT_TER10x18) +=3D font_ter10x18.o -font-objs-$(CONFIG_FONT_TER16x32) +=3D font_ter16x32.o -font-objs-$(CONFIG_FONT_6x8) +=3D font_6x8.o +# Built-in fonts +font-$(CONFIG_FONT_10x18) +=3D font_10x18.o +font-$(CONFIG_FONT_6x10) +=3D font_6x10.o +font-$(CONFIG_FONT_6x11) +=3D font_6x11.o +font-$(CONFIG_FONT_6x8) +=3D font_6x8.o +font-$(CONFIG_FONT_7x14) +=3D font_7x14.o +font-$(CONFIG_FONT_8x16) +=3D font_8x16.o +font-$(CONFIG_FONT_8x8) +=3D font_8x8.o +font-$(CONFIG_FONT_ACORN_8x8) +=3D font_acorn_8x8.o +font-$(CONFIG_FONT_MINI_4x6) +=3D font_mini_4x6.o +font-$(CONFIG_FONT_PEARL_8x8) +=3D font_pearl_8x8.o +font-$(CONFIG_FONT_SUN12x22) +=3D font_sun12x22.o +font-$(CONFIG_FONT_SUN8x16) +=3D font_sun8x16.o +font-$(CONFIG_FONT_TER10x18) +=3D font_ter10x18.o +font-$(CONFIG_FONT_TER16x32) +=3D font_ter16x32.o =20 -font-objs +=3D $(font-objs-y) - -obj-$(CONFIG_FONT_SUPPORT) +=3D font.o +obj-$(CONFIG_FONT_SUPPORT) +=3D font.o --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8581B3E868A for ; Fri, 27 Mar 2026 13:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616693; cv=none; b=NEbOAOGwCmLveNZi442u4UNvPs4bYYXjMilrhU9JiMA9A8dqv8qeJrESrZxdXZ4ibIZcpeJAmFqkF+ZOf/siOaMoNxTvWfHAMbJV/ap8h7UPaEovGd8MSIkcSFdPSj4MESrPsNXl7KaULLw/iGRQO6y23zZ+lJNLo0gOSnT5OVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616693; c=relaxed/simple; bh=GOIWEa9RuQ1ASPmVdz6+dIKrANd1nAtM9ByQxIsBqNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OqSQwiUn/Gn9imH3jY5JNjYVtG9FJPWYrXVNbKJjO3EghfmakccTXMe76u0HEqJDEhoC7xmHo5OkaS0JirlHK2Esk/JyhIuZRllDI3F6y9tKrhGMCLgObnn/JjFf1Prfs9NeCbxClBTBjueQmedC7UAQpjcBz3dWQI+uHz4XoV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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 661965BE43; Fri, 27 Mar 2026 13:04:37 +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 23B064A0B1; Fri, 27 Mar 2026 13:04:37 +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 oDCMB2WAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:37 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 05/10] lib/fonts: Implement glyph rotation Date: Fri, 27 Mar 2026 13:49:38 +0100 Message-ID: <20260327130431.59481-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 661965BE43 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Score: -4.00 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Move the glphy rotation helpers from fbcon to the font library. Wrap them behind clean interfaces. Also clear the output memory to zero. Previously, the implementation relied on the caller to do that. Go through the fbcon code and callers of the glyph-rotation helpers. In addition to the font rotation, there's also the cursor code, which uses the rotation helpers. The font-rotation relied on a single memset to zero for the whole font. This is now multiple memsets on each glyph. This will be sorted out when the font library also implements font rotation. Building glyph rotation in the font library still depends on CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=3Dy. If we get more users of the code, we can still add a dedicated Kconfig symbol to the font library. No changes have been made to the actual implementation of the rotate_*() and pattern_*() functions. These will be refactored as separate changes. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon_ccw.c | 4 +- drivers/video/fbdev/core/fbcon_cw.c | 4 +- drivers/video/fbdev/core/fbcon_rotate.c | 12 +- drivers/video/fbdev/core/fbcon_rotate.h | 71 ----------- include/linux/font.h | 8 ++ lib/fonts/Makefile | 1 + lib/fonts/font_rotate.c | 150 ++++++++++++++++++++++++ 7 files changed, 167 insertions(+), 83 deletions(-) create mode 100644 lib/fonts/font_rotate.c diff --git a/drivers/video/fbdev/core/fbcon_ccw.c b/drivers/video/fbdev/cor= e/fbcon_ccw.c index 96ef449ee6ac..72453a2aaca8 100644 --- a/drivers/video/fbdev/core/fbcon_ccw.c +++ b/drivers/video/fbdev/core/fbcon_ccw.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -344,8 +345,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_in= fo *info, bool enable, size =3D cur_height * width; while (size--) tmp[i++] =3D 0xff; - memset(mask, 0, w * vc->vc_font.width); - rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height); + font_glyph_rotate_270(tmp, vc->vc_font.width, vc->vc_font.height, mask); kfree(tmp); } =20 diff --git a/drivers/video/fbdev/core/fbcon_cw.c b/drivers/video/fbdev/core= /fbcon_cw.c index ea712654edae..5690fc1d7854 100644 --- a/drivers/video/fbdev/core/fbcon_cw.c +++ b/drivers/video/fbdev/core/fbcon_cw.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -327,8 +328,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_inf= o *info, bool enable, size =3D cur_height * width; while (size--) tmp[i++] =3D 0xff; - memset(mask, 0, w * vc->vc_font.width); - rotate_cw(tmp, mask, vc->vc_font.width, vc->vc_font.height); + font_glyph_rotate_90(tmp, vc->vc_font.width, vc->vc_font.height, mask); kfree(tmp); } =20 diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/= core/fbcon_rotate.c index 18575c5182db..588dc9d6758a 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -60,30 +61,25 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_d= ata *vc) } =20 dst =3D par->fontbuffer; - memset(dst, 0, par->fd_size); =20 switch (par->rotate) { case FB_ROTATE_UD: for (i =3D len; i--; ) { - rotate_ud(src, dst, vc->vc_font.width, - vc->vc_font.height); - + font_glyph_rotate_180(src, vc->vc_font.width, vc->vc_font.height, dst); src +=3D s_cellsize; dst +=3D d_cellsize; } break; case FB_ROTATE_CW: for (i =3D len; i--; ) { - rotate_cw(src, dst, vc->vc_font.width, - vc->vc_font.height); + font_glyph_rotate_90(src, vc->vc_font.width, vc->vc_font.height, dst); src +=3D s_cellsize; dst +=3D d_cellsize; } break; case FB_ROTATE_CCW: for (i =3D len; i--; ) { - rotate_ccw(src, dst, vc->vc_font.width, - vc->vc_font.height); + font_glyph_rotate_270(src, vc->vc_font.width, vc->vc_font.height, dst); src +=3D s_cellsize; dst +=3D d_cellsize; } diff --git a/drivers/video/fbdev/core/fbcon_rotate.h b/drivers/video/fbdev/= core/fbcon_rotate.h index 8cb019e8a9c0..725bcae2df61 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.h +++ b/drivers/video/fbdev/core/fbcon_rotate.h @@ -19,77 +19,6 @@ (fb_scrollmode(s) =3D=3D SCROLL_REDRAW || fb_scrollmode(s) =3D=3D = SCROLL_MOVE || !(i)->fix.xpanstep) ? \ (i)->var.xres : (i)->var.xres_virtual; }) =20 - -static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pa= t) -{ - u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; - - pat +=3Dindex; - return (*pat) & (0x80 >> bit); -} - -static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat) -{ - u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; - - pat +=3D index; - - (*pat) |=3D 0x80 >> bit; -} - -static inline void rotate_ud(const char *in, char *out, u32 width, u32 hei= ght) -{ - int i, j; - int shift =3D (8 - (width % 8)) & 7; - - width =3D (width + 7) & ~7; - - for (i =3D 0; i < height; i++) { - for (j =3D 0; j < width - shift; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(width - (1 + j + shift), - height - (1 + i), - width, out); - } - - } -} - -static inline void rotate_cw(const char *in, char *out, u32 width, u32 hei= ght) -{ - int i, j, h =3D height, w =3D width; - int shift =3D (8 - (height % 8)) & 7; - - width =3D (width + 7) & ~7; - height =3D (height + 7) & ~7; - - for (i =3D 0; i < h; i++) { - for (j =3D 0; j < w; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(height - 1 - i - shift, j, - height, out); - - } - } -} - -static inline void rotate_ccw(const char *in, char *out, u32 width, u32 he= ight) -{ - int i, j, h =3D height, w =3D width; - int shift =3D (8 - (width % 8)) & 7; - - width =3D (width + 7) & ~7; - height =3D (height + 7) & ~7; - - for (i =3D 0; i < h; i++) { - for (j =3D 0; j < w; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(i, width - 1 - j - shift, - height, out); - } - } -} - int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc); =20 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION) diff --git a/include/linux/font.h b/include/linux/font.h index 3bd49d914b22..0a240dd70422 100644 --- a/include/linux/font.h +++ b/include/linux/font.h @@ -104,6 +104,14 @@ unsigned int font_data_size(font_data_t *fd); bool font_data_is_equal(font_data_t *lhs, font_data_t *rhs); int font_data_export(font_data_t *fd, struct console_font *font, unsigned = int vpitch); =20 +/* font_rotate.c */ +void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, = unsigned int height, + unsigned char *out); +void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width,= unsigned int height, + unsigned char *out); +void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width,= unsigned int height, + unsigned char *out); + /* * Font description */ diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile index 3268d344c0a1..32ece0e265c8 100644 --- a/lib/fonts/Makefile +++ b/lib/fonts/Makefile @@ -2,6 +2,7 @@ # Font handling =20 font-y :=3D fonts.o +font-$(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION) +=3D font_rotate.o =20 # Built-in fonts font-$(CONFIG_FONT_10x18) +=3D font_10x18.o diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c new file mode 100644 index 000000000000..3e0a19c889f3 --- /dev/null +++ b/lib/fonts/font_rotate.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Font rotation + * + * Copyright (C) 2005 Antonino Daplas + * + * This file is subject to the terms and conditions of the GNU General Pub= lic + * License. See the file COPYING in the main directory of this archive for + * more details. + */ + +#include +#include +#include + +#include "font.h" + +static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pa= t) +{ + u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; + + pat +=3D index; + return (*pat) & (0x80 >> bit); +} + +static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat) +{ + u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; + + pat +=3D index; + + (*pat) |=3D 0x80 >> bit; +} + +static inline void rotate_cw(const char *in, char *out, u32 width, u32 hei= ght) +{ + int i, j, h =3D height, w =3D width; + int shift =3D (8 - (height % 8)) & 7; + + width =3D (width + 7) & ~7; + height =3D (height + 7) & ~7; + + for (i =3D 0; i < h; i++) { + for (j =3D 0; j < w; j++) { + if (pattern_test_bit(j, i, width, in)) + pattern_set_bit(height - 1 - i - shift, j, + height, out); + } + } +} + +/** + * font_glyph_rotate_90 - Rotate a glyph pattern by 90=C2=B0 in clockwise = direction + * @glyph: The glyph to rotate + * @width: The glyph width in bits per scanline + * @height: The number of scanlines in the glyph + * @out: The rotated glyph bitmap + * + * The parameters @width and @height refer to the input glyph given in @gl= yph. + * The caller has to provide the output buffer @out of sufficient size to = hold + * the rotated glyph. Rotating by 90=C2=B0 flips the width and height for = the output + * glyph. Depending on the glyph pitch, the size of the output glyph can be + * different then the size of the input. Caller shave to take this into ac= count + * when allocating the output memory. + */ +void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, = unsigned int height, + unsigned char *out) +{ + memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ + + rotate_cw(glyph, out, width, height); +} +EXPORT_SYMBOL_GPL(font_glyph_rotate_90); + +static inline void rotate_ud(const char *in, char *out, u32 width, u32 hei= ght) +{ + int i, j; + int shift =3D (8 - (width % 8)) & 7; + + width =3D (width + 7) & ~7; + + for (i =3D 0; i < height; i++) { + for (j =3D 0; j < width - shift; j++) { + if (pattern_test_bit(j, i, width, in)) + pattern_set_bit(width - (1 + j + shift), + height - (1 + i), + width, out); + } + } +} + +/** + * font_glyph_rotate_180 - Rotate a glyph pattern by 180=C2=B0 + * @glyph: The glyph to rotate + * @width: The glyph width in bits per scanline + * @height: The number of scanlines in the glyph + * @out: The rotated glyph bitmap + * + * The parameters @width and @height refer to the input glyph given in @gl= yph. + * The caller has to provide the output buffer @out of sufficient size to = hold + * the rotated glyph. + */ +void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width,= unsigned int height, + unsigned char *out) +{ + memset(out, 0, font_glyph_size(width, height)); + + rotate_ud(glyph, out, width, height); +} +EXPORT_SYMBOL_GPL(font_glyph_rotate_180); + +static inline void rotate_ccw(const char *in, char *out, u32 width, u32 he= ight) +{ + int i, j, h =3D height, w =3D width; + int shift =3D (8 - (width % 8)) & 7; + + width =3D (width + 7) & ~7; + height =3D (height + 7) & ~7; + + for (i =3D 0; i < h; i++) { + for (j =3D 0; j < w; j++) { + if (pattern_test_bit(j, i, width, in)) + pattern_set_bit(i, width - 1 - j - shift, + height, out); + } + } +} + +/** + * font_glyph_rotate_270 - Rotate a glyph pattern by 270=C2=B0 in clockwis= e direction + * @glyph: The glyph to rotate + * @width: The glyph width in bits per scanline + * @height: The number of scanlines in the glyph + * @out: The rotated glyph bitmap + * + * The parameters @width and @height refer to the input glyph given in @gl= yph. + * The caller has to provide the output buffer @out of sufficient size to = hold + * the rotated glyph. Rotating by 270=C2=B0 flips the width and height for= the output + * glyph. Depending on the glyph pitch, the size of the output glyph can be + * different then the size of the input. Caller shave to take this into ac= count + * when allocating the output memory. + */ +void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width,= unsigned int height, + unsigned char *out) +{ + memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ + + rotate_ccw(glyph, out, width, height); +} +EXPORT_SYMBOL_GPL(font_glyph_rotate_270); --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 798BF3EAC7D for ; Fri, 27 Mar 2026 13:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616700; cv=none; b=puEdwlSd1ySZkoPZcMnZmxrG29kVMjSQrLHwBoCAcqGncvoAftPwV5AHLneUY+/cHg1vTRinRRXvUai+M6QakDtGHKUuVoMBxIpumzA3PxpUK93y5Wj4WbMgRnBqHtKQEJd0bscW4qgrilSFIOZDVamBjSiYafgwIIZR5127ySQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616700; c=relaxed/simple; bh=SwyFcBTtjprZ6cZs5AKJ5D4ZGP++skRWaDNUudjAcrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mqrylwT30ojdXnoxe8mDE+GtVOtezlF5tM7/5qGGaK34MiKH7lsKCvPWHATCizYUZtCBd6aBcz/yO+7tyzz7X5zZuRXsgwaoLdmpwMUN089dqXsTYmjTqcAXmYHHGrqOp66iRhrOMw0JJicUE2TRFf2cTeBRggk8wkIiUiLgSQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=b11CVxWD; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=XZYegzk9; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=b11CVxWD; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=XZYegzk9; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="b11CVxWD"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XZYegzk9"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="b11CVxWD"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XZYegzk9" 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 ACF214D395; Fri, 27 Mar 2026 13:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616677; 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=7VcpVHM73mKA2ZM9jxQN+8VqSFFJcUK690qm6q5lkVM=; b=b11CVxWDf/kD1SSDdBCmx+N4l016RPUCA1mHO5f3fVsYKfi5DZ0h9Qky8l2EMBwg5QpeSl iIm0QHA7bUOVKUhuwP5E6j5NPjRTXwWYt///SOruU8ajrBPc1BbvnF5buW610vaNejYx0O wW4LPI1WQxeMZAGDglbV7Zm/NrsUGW8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616677; 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=7VcpVHM73mKA2ZM9jxQN+8VqSFFJcUK690qm6q5lkVM=; b=XZYegzk9hsQvA0PqhQGn3HWsFR3A9RCTgce1S2lYxngpj6J/sukYCS7AUh99nKNDfk1P3e nOnc2NyC/OBkz1Cg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616677; 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=7VcpVHM73mKA2ZM9jxQN+8VqSFFJcUK690qm6q5lkVM=; b=b11CVxWDf/kD1SSDdBCmx+N4l016RPUCA1mHO5f3fVsYKfi5DZ0h9Qky8l2EMBwg5QpeSl iIm0QHA7bUOVKUhuwP5E6j5NPjRTXwWYt///SOruU8ajrBPc1BbvnF5buW610vaNejYx0O wW4LPI1WQxeMZAGDglbV7Zm/NrsUGW8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616677; 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=7VcpVHM73mKA2ZM9jxQN+8VqSFFJcUK690qm6q5lkVM=; b=XZYegzk9hsQvA0PqhQGn3HWsFR3A9RCTgce1S2lYxngpj6J/sukYCS7AUh99nKNDfk1P3e nOnc2NyC/OBkz1Cg== 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 6CF624A0A2; Fri, 27 Mar 2026 13:04:37 +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 WA9mGWWAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:37 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 06/10] lib/fonts: Refactor glyph-pattern helpers Date: Fri, 27 Mar 2026 13:49:39 +0100 Message-ID: <20260327130431.59481-7-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_TO(0.00)[gmx.de,linuxfoundation.org,kernel.org,ffwll.ch,ravnborg.org]; RCPT_COUNT_SEVEN(0.00)[10]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmx.de] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Change the signatures of the pattern helpers to align them with other font-glyph helpers: use the font_glyph_ prefix and pass the glyph buffer first. Calculating the position of the involved bit is somewhat obfuscated in the original implementation. Move it into the new helper __font_glphy_pos() and use the result as array index and bit position. Note that these bit helpers use a bit pitch, while other code uses a byte pitch. This is intentional an required here. Signed-off-by: Thomas Zimmermann --- lib/fonts/font_rotate.c | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c index 3e0a19c889f3..cfaf5b98f49a 100644 --- a/lib/fonts/font_rotate.c +++ b/lib/fonts/font_rotate.c @@ -15,21 +15,33 @@ =20 #include "font.h" =20 -static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pa= t) +static unsigned int __font_glyph_pos(unsigned int x, unsigned int y, unsig= ned int bit_pitch, + unsigned int *bit) { - u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; + unsigned int off =3D y * bit_pitch + x; + unsigned int bit_shift =3D off % 8; =20 - pat +=3D index; - return (*pat) & (0x80 >> bit); + *bit =3D 0x80 >> bit_shift; /* MSB has position 0, LSB has position 7 */ + + return off / 8; } =20 -static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat) +static bool font_glyph_test_bit(const unsigned char *glyph, unsigned int x= , unsigned int y, + unsigned int bit_pitch) { - u32 tmp =3D (y * pitch) + x, index =3D tmp / 8, bit =3D tmp % 8; + unsigned int bit; + unsigned int i =3D __font_glyph_pos(x, y, bit_pitch, &bit); + + return glyph[i] & bit; +} =20 - pat +=3D index; +static void font_glyph_set_bit(unsigned char *glyph, unsigned int x, unsig= ned int y, + unsigned int bit_pitch) +{ + unsigned int bit; + unsigned int i =3D __font_glyph_pos(x, y, bit_pitch, &bit); =20 - (*pat) |=3D 0x80 >> bit; + glyph[i] |=3D bit; } =20 static inline void rotate_cw(const char *in, char *out, u32 width, u32 hei= ght) @@ -42,9 +54,8 @@ static inline void rotate_cw(const char *in, char *out, u= 32 width, u32 height) =20 for (i =3D 0; i < h; i++) { for (j =3D 0; j < w; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(height - 1 - i - shift, j, - height, out); + if (font_glyph_test_bit(in, j, i, width)) + font_glyph_set_bit(out, height - 1 - i - shift, j, height); } } } @@ -81,10 +92,9 @@ static inline void rotate_ud(const char *in, char *out, = u32 width, u32 height) =20 for (i =3D 0; i < height; i++) { for (j =3D 0; j < width - shift; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(width - (1 + j + shift), - height - (1 + i), - width, out); + if (font_glyph_test_bit(in, j, i, width)) + font_glyph_set_bit(out, width - (1 + j + shift), + height - (1 + i), width); } } } @@ -119,9 +129,8 @@ static inline void rotate_ccw(const char *in, char *out= , u32 width, u32 height) =20 for (i =3D 0; i < h; i++) { for (j =3D 0; j < w; j++) { - if (pattern_test_bit(j, i, width, in)) - pattern_set_bit(i, width - 1 - j - shift, - height, out); + if (font_glyph_test_bit(in, j, i, width)) + font_glyph_set_bit(out, i, width - 1 - j - shift, height); } } } --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 859083E6DF2 for ; Fri, 27 Mar 2026 13:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616705; cv=none; b=Y4RiQ/oJB/vY2xmxG6GJ0tR6ItB2zNK6tpkwPqKRVmX903CsrXFOBjHDl09LRPbl6A60zvDfiCuvtrhJTKfgLuUmrJtoTQwGiAhFxhT7pFT1X3SV034jbBph2nvMsGA3MuIfWW58YL46bE8uTjJpJO3s9aKRS98LlybA5EVrSTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616705; c=relaxed/simple; bh=nVdgDbZb8tmD06udRURI81bPSo70ic+a3xXeWwPo2eU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cLgZhjyBBMYun9nleErAI4dJLipWoOQJK0Gtv8oNRKszo4Uu6bJ1Dn9AvtlyRyUzlI4IhBp3+/U20C6GK57NnTpAhaErm47IucENWlJJqAvQF/DzXvHdyey7RqSFWgNNMT2ftTGqkPsJ+w+k57RM89WZCB7WUCdixm/VxaGU6pk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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 035D34D39F; Fri, 27 Mar 2026 13:04:38 +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 B44294A0B1; Fri, 27 Mar 2026 13:04:37 +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 WIjRKmWAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:37 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 07/10] lib/fonts: Refactor glyph-rotation helpers Date: Fri, 27 Mar 2026 13:49:40 +0100 Message-ID: <20260327130431.59481-8-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 035D34D39F X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Change the signatures of the glyph-rotation helpers to match their public interfaces. Drop the inline qualifier. Rename several variables to better match their meaning. Especially rename variables to bit_pitch (or a variant thereof) if they store a pitch value in bits per scanline. The original code is fairly confusing about this. Move the calculation of the bit pitch into the new helper font_glyph_bit_pitch(). Signed-off-by: Thomas Zimmermann --- lib/fonts/font_rotate.c | 85 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c index cfaf5b98f49a..f1e441a931ab 100644 --- a/lib/fonts/font_rotate.c +++ b/lib/fonts/font_rotate.c @@ -15,6 +15,12 @@ =20 #include "font.h" =20 +/* number of bits per line */ +static unsigned int font_glyph_bit_pitch(unsigned int width) +{ + return round_up(width, 8); +} + static unsigned int __font_glyph_pos(unsigned int x, unsigned int y, unsig= ned int bit_pitch, unsigned int *bit) { @@ -44,18 +50,21 @@ static void font_glyph_set_bit(unsigned char *glyph, un= signed int x, unsigned in glyph[i] |=3D bit; } =20 -static inline void rotate_cw(const char *in, char *out, u32 width, u32 hei= ght) +static void __font_glyph_rotate_90(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j, h =3D height, w =3D width; - int shift =3D (8 - (height % 8)) & 7; - - width =3D (width + 7) & ~7; - height =3D (height + 7) & ~7; - - for (i =3D 0; i < h; i++) { - for (j =3D 0; j < w; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, height - 1 - i - shift, j, height); + unsigned int x, y; + unsigned int shift =3D (8 - (height % 8)) & 7; + unsigned int bit_pitch =3D font_glyph_bit_pitch(width); + unsigned int out_bit_pitch =3D font_glyph_bit_pitch(height); + + for (y =3D 0; y < height; y++) { + for (x =3D 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) { + font_glyph_set_bit(out, out_bit_pitch - 1 - y - shift, x, + out_bit_pitch); + } } } } @@ -79,22 +88,24 @@ void font_glyph_rotate_90(const unsigned char *glyph, u= nsigned int width, unsign { memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ =20 - rotate_cw(glyph, out, width, height); + __font_glyph_rotate_90(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_90); =20 -static inline void rotate_ud(const char *in, char *out, u32 width, u32 hei= ght) +static void __font_glyph_rotate_180(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j; - int shift =3D (8 - (width % 8)) & 7; - - width =3D (width + 7) & ~7; - - for (i =3D 0; i < height; i++) { - for (j =3D 0; j < width - shift; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, width - (1 + j + shift), - height - (1 + i), width); + unsigned int x, y; + unsigned int shift =3D (8 - (width % 8)) & 7; + unsigned int bit_pitch =3D font_glyph_bit_pitch(width); + + for (y =3D 0; y < height; y++) { + for (x =3D 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) { + font_glyph_set_bit(out, width - (1 + x + shift), height - (1 + y), + bit_pitch); + } } } } @@ -115,22 +126,24 @@ void font_glyph_rotate_180(const unsigned char *glyph= , unsigned int width, unsig { memset(out, 0, font_glyph_size(width, height)); =20 - rotate_ud(glyph, out, width, height); + __font_glyph_rotate_180(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_180); =20 -static inline void rotate_ccw(const char *in, char *out, u32 width, u32 he= ight) +static void __font_glyph_rotate_270(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j, h =3D height, w =3D width; - int shift =3D (8 - (width % 8)) & 7; - - width =3D (width + 7) & ~7; - height =3D (height + 7) & ~7; - - for (i =3D 0; i < h; i++) { - for (j =3D 0; j < w; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, i, width - 1 - j - shift, height); + unsigned int x, y; + unsigned int shift =3D (8 - (width % 8)) & 7; + unsigned int bit_pitch =3D font_glyph_bit_pitch(width); + unsigned int out_bit_pitch =3D font_glyph_bit_pitch(height); + + for (y =3D 0; y < height; y++) { + for (x =3D 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) + font_glyph_set_bit(out, y, bit_pitch - 1 - x - shift, + out_bit_pitch); } } } @@ -154,6 +167,6 @@ void font_glyph_rotate_270(const unsigned char *glyph, = unsigned int width, unsig { memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ =20 - rotate_ccw(glyph, out, width, height); + __font_glyph_rotate_270(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_270); --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF2D33E959F for ; Fri, 27 Mar 2026 13:05:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616712; cv=none; b=TkTjkwqSZGECOc1sHxudyDOj1omHj/h3r3a7zB6z6J8R7tP2uTTGCBCwG7HZTocGo93Aofoq8Uyn0AJfp6tN3nb10uy7nIosiFHO+lWpHqZs07N2WC8mzDSDt9N8qaP1hnj2jmKBlFhTQtjHKsbJgKD2T9bpBbg8P3g4fZG553E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616712; c=relaxed/simple; bh=RB+M8lR5XN1us0zSmwto8GBAjybD+BpTQhA1a9Wbrt4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pc3OAgwFs3VxjC6MgDnZnmPRk7ZrDzgnUwRMGEZ8Md2aplqHwzbwIdLOkuzinI3vSOiiz4juWAKjex0y/yKqBANpmwhS6KlkAdeOqUh/rhBb8LpD1PJMecnRjaTlPAt/fFSV1X/QAgTkmwYKVK7QR7IUBkBcwiW83+CFaoxErPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=YnqJ4KJJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=S5dkZYAR; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=YnqJ4KJJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=S5dkZYAR; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="YnqJ4KJJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="S5dkZYAR"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="YnqJ4KJJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="S5dkZYAR" 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 4C2494D347; Fri, 27 Mar 2026 13:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UXbch6n2enq8wiRbR7KUsLz+dTkbA9k9SyrEF5tA2ts=; b=YnqJ4KJJEjfT9aXeAppynAeWrYSyAI97Qrj+16GoREp8oYEOVcb3L77umwSTKRPL0fp45m 0Cmt5JMOKZB02D3h8ydah/h4pKmSkwrbX65EEBTb8A9n37ztjGzZuBwT7KnJwtA7UGDbVo 6c42oTS/mo0aNE9g0T00M3KEy84Dlxk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UXbch6n2enq8wiRbR7KUsLz+dTkbA9k9SyrEF5tA2ts=; b=S5dkZYARHEFkJgd0aRXZ99canoOYm79S2FE5vsmRlYDM1/v1EUFGEm93R1HI1Jx/ri+sh6 R0uEedLl6Ai/doBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UXbch6n2enq8wiRbR7KUsLz+dTkbA9k9SyrEF5tA2ts=; b=YnqJ4KJJEjfT9aXeAppynAeWrYSyAI97Qrj+16GoREp8oYEOVcb3L77umwSTKRPL0fp45m 0Cmt5JMOKZB02D3h8ydah/h4pKmSkwrbX65EEBTb8A9n37ztjGzZuBwT7KnJwtA7UGDbVo 6c42oTS/mo0aNE9g0T00M3KEy84Dlxk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UXbch6n2enq8wiRbR7KUsLz+dTkbA9k9SyrEF5tA2ts=; b=S5dkZYARHEFkJgd0aRXZ99canoOYm79S2FE5vsmRlYDM1/v1EUFGEm93R1HI1Jx/ri+sh6 R0uEedLl6Ai/doBg== 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 095744A0A2; Fri, 27 Mar 2026 13:04:38 +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 mHQaAWaAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:38 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 08/10] lib/fonts: Implement font rotation Date: Fri, 27 Mar 2026 13:49:41 +0100 Message-ID: <20260327130431.59481-9-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-7.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_TO(0.00)[gmx.de,linuxfoundation.org,kernel.org,ffwll.ch,ravnborg.org]; FREEMAIL_ENVRCPT(0.00)[gmx.de]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_SEVEN(0.00)[10]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email] X-Spam-Flag: NO X-Spam-Score: -7.30 X-Spam-Level: Move the core of fbcon's font-rotation code to the font library as the new helper font_data_rotate(). The code can rotate in steps of 90=C2=B0. For completeness, it also copies the glyph data for multiples of 360=C2=B0. Bring back the memset optimization. A memset to 0 again clears the whole glyph output buffer. Then use the internal rotation helpers on the cleared output. Fbcon's original implementation worked like this, but lost it during refactoring. Replace fbcon's font-rotation code with the new implementations. All that's left to do for fbcon is to maintain its internal fbcon state. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.h | 2 +- drivers/video/fbdev/core/fbcon_rotate.c | 78 +++++------------- include/linux/font.h | 3 + lib/fonts/font_rotate.c | 103 ++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 60 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fb= con.h index 1e3c1ef84762..1793f34a6c84 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -86,7 +86,7 @@ struct fbcon_par { const u8 *fontdata; u8 *cursor_src; u32 cursor_size; - u32 fd_size; + size_t fd_size; =20 const struct fbcon_bitops *bitops; }; diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/= core/fbcon_rotate.c index 588dc9d6758a..74206f5a6e98 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -8,84 +8,44 @@ * more details. */ =20 -#include -#include -#include +#include #include #include -#include -#include -#include + #include "fbcon.h" #include "fbcon_rotate.h" =20 int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc) { struct fbcon_par *par =3D info->fbcon_par; - int len, err =3D 0; - int s_cellsize, d_cellsize, i; - const u8 *src; - u8 *dst; + unsigned char *fontbuffer; + int ret; =20 if (vc->vc_font.data =3D=3D par->fontdata && par->p->con_rotate =3D=3D par->cur_rotate) - goto finished; + return 0; =20 - src =3D par->fontdata =3D vc->vc_font.data; + par->fontdata =3D vc->vc_font.data; par->cur_rotate =3D par->p->con_rotate; - len =3D vc->vc_font.charcount; - s_cellsize =3D font_glyph_size(vc->vc_font.width, vc->vc_font.height); - d_cellsize =3D s_cellsize; - - if (par->rotate =3D=3D FB_ROTATE_CW || - par->rotate =3D=3D FB_ROTATE_CCW) - d_cellsize =3D font_glyph_size(vc->vc_font.height, vc->vc_font.width); =20 if (info->fbops->fb_sync) info->fbops->fb_sync(info); =20 - if (par->fd_size < d_cellsize * len) { - kfree(par->fontbuffer); - par->fontbuffer =3D NULL; - par->fd_size =3D 0; - - dst =3D kmalloc_array(len, d_cellsize, GFP_KERNEL); - - if (dst =3D=3D NULL) { - err =3D -ENOMEM; - goto finished; - } - - par->fd_size =3D d_cellsize * len; - par->fontbuffer =3D dst; + fontbuffer =3D font_data_rotate(par->p->fontdata, vc->vc_font.width, + vc->vc_font.height, vc->vc_font.charcount, + par->rotate, par->fontbuffer, &par->fd_size); + if (IS_ERR(fontbuffer)) { + ret =3D PTR_ERR(fontbuffer); + goto err_kfree; } =20 - dst =3D par->fontbuffer; + par->fontbuffer =3D fontbuffer; =20 - switch (par->rotate) { - case FB_ROTATE_UD: - for (i =3D len; i--; ) { - font_glyph_rotate_180(src, vc->vc_font.width, vc->vc_font.height, dst); - src +=3D s_cellsize; - dst +=3D d_cellsize; - } - break; - case FB_ROTATE_CW: - for (i =3D len; i--; ) { - font_glyph_rotate_90(src, vc->vc_font.width, vc->vc_font.height, dst); - src +=3D s_cellsize; - dst +=3D d_cellsize; - } - break; - case FB_ROTATE_CCW: - for (i =3D len; i--; ) { - font_glyph_rotate_270(src, vc->vc_font.width, vc->vc_font.height, dst); - src +=3D s_cellsize; - dst +=3D d_cellsize; - } - break; - } + return 0; + +err_kfree: + kfree(par->fontbuffer); + par->fontbuffer =3D NULL; /* clear here to avoid output */ =20 -finished: - return err; + return ret; } diff --git a/include/linux/font.h b/include/linux/font.h index 0a240dd70422..6845f02d739a 100644 --- a/include/linux/font.h +++ b/include/linux/font.h @@ -111,6 +111,9 @@ void font_glyph_rotate_180(const unsigned char *glyph, = unsigned int width, unsig unsigned char *out); void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width,= unsigned int height, unsigned char *out); +unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsig= ned int height, + unsigned int charcount, unsigned int steps, + unsigned char *buf, size_t *bufsize); =20 /* * Font description diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c index f1e441a931ab..d8c8973310c2 100644 --- a/lib/fonts/font_rotate.c +++ b/lib/fonts/font_rotate.c @@ -9,8 +9,11 @@ * more details. */ =20 +#include #include #include +#include +#include #include =20 #include "font.h" @@ -170,3 +173,103 @@ void font_glyph_rotate_270(const unsigned char *glyph= , unsigned int width, unsig __font_glyph_rotate_270(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_270); + +/** + * font_data_rotate - Rotate font data by multiples of 90=C2=B0 + * @fd: The font data to rotate + * @width: The glyph width in bits per scanline + * @height: The number of scanlines in the glyph + * @charcount: The number of glyphs in the font + * @steps: Number of rotation steps of 90=C2=B0 + * @buf: Preallocated output buffer; can be NULL + * @bufsize: The size of @buf in bytes; can be NULL + * + * The parameters @width and @height refer to the visible number of pixels + * and scanlines in a single glyph. The number of glyphs is given in @char= count. + * Rotation happens in steps of 90=C2=B0. The @steps parameter can have an= y value, + * but only 0 to 3 produce distinct results. With 4 or higher, a full rota= tion + * has been performed. You can pass any value for @steps and the helper wi= ll + * perform the appropriate rotation. Note that the returned buffer is not + * compatible with font_data_t. It only contains glphy data in the same fo= rmat + * as returned by font_data_buf(). Callers are responsible to free the ret= urned + * buffer with kfree(). Font rotation typically happens when displays get + * re-oriented. To avoid unnecessary re-allocation of the memory buffer, t= he + * caller can pass in an earlier result buffer in @buf for reuse. The buff= er + * size of given and returned in @bufsize. The allocation semantics are co= mpatible + * with krealloc(). + * + * Returns: + * A buffer with rotated glyphs on success, or an error pointer otherwise + */ +unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsig= ned int height, + unsigned int charcount, unsigned int steps, + unsigned char *buf, size_t *bufsize) +{ + const unsigned char *src =3D font_data_buf(fd); + unsigned int s_cellsize =3D font_glyph_size(width, height); + unsigned int d_cellsize, i; + unsigned char *dst; + size_t size; + + steps %=3D 4; + + switch (steps) { + case 0: + case 2: + d_cellsize =3D s_cellsize; + break; + case 1: + case 3: + d_cellsize =3D font_glyph_size(height, width); /* flip width/height */ + break; + } + + if (check_mul_overflow(charcount, d_cellsize, &size)) + return ERR_PTR(-EINVAL); + + if (!buf || !bufsize || size > *bufsize) { + dst =3D kmalloc_array(charcount, d_cellsize, GFP_KERNEL); + if (!dst) + return ERR_PTR(-ENOMEM); + + kfree(buf); + buf =3D dst; + if (bufsize) + *bufsize =3D size; + } else { + dst =3D buf; + } + + switch (steps) { + case 0: + memcpy(dst, src, size); + break; + case 1: + memset(dst, 0, size); + for (i =3D 0; i < charcount; ++i) { + __font_glyph_rotate_90(src, width, height, dst); + src +=3D s_cellsize; + dst +=3D d_cellsize; + } + break; + case 2: + memset(dst, 0, size); + for (i =3D 0; i < charcount; ++i) { + __font_glyph_rotate_180(src, width, height, dst); + src +=3D s_cellsize; + dst +=3D d_cellsize; + } + break; + case 3: + memset(dst, 0, size); + for (i =3D 0; i < charcount; ++i) { + __font_glyph_rotate_270(src, width, height, dst); + src +=3D s_cellsize; + dst +=3D d_cellsize; + } + break; + } + + return buf; +} +EXPORT_SYMBOL_GPL(font_data_rotate); --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED2A83E6393 for ; Fri, 27 Mar 2026 13:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616700; cv=none; b=kP2Q9/36j+4GYZtNHyTQvPqrBUBJQvqPlFJPyq7yLgEd0Mz5w8DEkUYdfnbWebRvGp8nyb/1M8FcmJYPBOLJVZjTZwCT6Oru+HuF7coplA9IRuMbZWHqW9eN7arzer3FsN54zVbFN1pW3BSHSbKOoNnia7v45mtob8YcRhL/Dyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616700; c=relaxed/simple; bh=SbQU8AAmc66jXISs63Ig5qeDNO69QwvMItcyRRibDBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XjC3ACDYFQR7eO4hn5lFTtrc8CgWRBhQgZzRuRbhY7BVs8D6BvNnEWWsh7Vr6RgKZK7PWMgjmDYMgTQEuqCaFMcfrlCF+w9mNWMxB4TGOImW1PtVVSSsr4DraoqMAtO9xG1UOef0HdW1JEdcUY7OVYJ4SwJZVo1Q9BgIL/SvTV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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 958BC5BE54; Fri, 27 Mar 2026 13:04:38 +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 53AAD4A0B1; Fri, 27 Mar 2026 13:04:38 +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 UJr9EmaAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:38 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 09/10] fbcon: Fill cursor mask in helper function Date: Fri, 27 Mar 2026 13:49:42 +0100 Message-ID: <20260327130431.59481-10-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 958BC5BE54 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Fbcon creates a cursor shape on the fly from the user-configured settings. The logic to create a glyph with the cursor's bitmap mask is duplicated in four places. In the cases that involve console rotation, the implementation further rotates the cursor glyph for displaying. Consolidate all cursor-mask creation in a single helper. Update the callers accordingly. For console rotation, use the glyph helpers to rotate the created cursor glyph to the correct orientation. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/bitblit.c | 35 ++----------------- drivers/video/fbdev/core/fbcon.c | 40 ++++++++++++++++++++++ drivers/video/fbdev/core/fbcon.h | 2 ++ drivers/video/fbdev/core/fbcon_ccw.c | 51 ++++++---------------------- drivers/video/fbdev/core/fbcon_cw.c | 51 ++++++---------------------- drivers/video/fbdev/core/fbcon_ud.c | 50 +++++++-------------------- 6 files changed, 78 insertions(+), 151 deletions(-) diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/= bitblit.c index 7478accea8ec..65681dcc5930 100644 --- a/drivers/video/fbdev/core/bitblit.c +++ b/drivers/video/fbdev/core/bitblit.c @@ -329,46 +329,17 @@ static void bit_cursor(struct vc_data *vc, struct fb_= info *info, bool enable, vc->vc_cursor_type !=3D par->p->cursor_shape || par->cursor_state.mask =3D=3D NULL || par->cursor_reset) { - char *mask =3D kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC); - int cur_height, size, i =3D 0; - u8 msk =3D 0xff; + unsigned char *mask =3D kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC); =20 if (!mask) return; + fbcon_fill_cursor_mask(par, vc, mask); =20 kfree(par->cursor_state.mask); - par->cursor_state.mask =3D mask; + par->cursor_state.mask =3D (const char *)mask; =20 par->p->cursor_shape =3D vc->vc_cursor_type; cursor.set |=3D FB_CUR_SETSHAPE; - - switch (CUR_SIZE(par->p->cursor_shape)) { - case CUR_NONE: - cur_height =3D 0; - break; - case CUR_UNDERLINE: - cur_height =3D (vc->vc_font.height < 10) ? 1 : 2; - break; - case CUR_LOWER_THIRD: - cur_height =3D vc->vc_font.height/3; - break; - case CUR_LOWER_HALF: - cur_height =3D vc->vc_font.height >> 1; - break; - case CUR_TWO_THIRDS: - cur_height =3D (vc->vc_font.height << 1)/3; - break; - case CUR_BLOCK: - default: - cur_height =3D vc->vc_font.height; - break; - } - size =3D (vc->vc_font.height - cur_height) * w; - while (size--) - mask[i++] =3D ~msk; - size =3D cur_height * w; - while (size--) - mask[i++] =3D msk; } =20 par->cursor_state.enable =3D enable && !use_sw; diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 8641b0b3edc4..345d9aa193f0 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -446,6 +446,46 @@ static void fbcon_del_cursor_work(struct fb_info *info) cancel_delayed_work_sync(&par->cursor_work); } =20 +void fbcon_fill_cursor_mask(struct fbcon_par *par, struct vc_data *vc, uns= igned char *mask) +{ + static const unsigned char pattern =3D 0xff; + unsigned int pitch =3D vc_font_pitch(&vc->vc_font); + unsigned int cur_height, size; + + switch (CUR_SIZE(vc->vc_cursor_type)) { + case CUR_NONE: + cur_height =3D 0; + break; + case CUR_UNDERLINE: + if (vc->vc_font.height < 10) + cur_height =3D 1; + else + cur_height =3D 2; + break; + case CUR_LOWER_THIRD: + cur_height =3D vc->vc_font.height / 3; + break; + case CUR_LOWER_HALF: + cur_height =3D vc->vc_font.height / 2; + break; + case CUR_TWO_THIRDS: + cur_height =3D (vc->vc_font.height * 2) / 3; + break; + case CUR_BLOCK: + default: + cur_height =3D vc->vc_font.height; + break; + } + + size =3D (vc->vc_font.height - cur_height) * pitch; + while (size--) + *mask++ =3D (unsigned char)~pattern; + + size =3D cur_height * pitch; + while (size--) + *mask++ =3D pattern; +} + #ifndef MODULE static int __init fb_console_setup(char *this_opt) { diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fb= con.h index 1793f34a6c84..bb0727b70631 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -192,6 +192,8 @@ extern void fbcon_set_tileops(struct vc_data *vc, struc= t fb_info *info); extern void fbcon_set_bitops_ur(struct fbcon_par *par); extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor); =20 +void fbcon_fill_cursor_mask(struct fbcon_par *par, struct vc_data *vc, uns= igned char *mask); + #define FBCON_ATTRIBUTE_UNDERLINE 1 #define FBCON_ATTRIBUTE_REVERSE 2 #define FBCON_ATTRIBUTE_BOLD 4 diff --git a/drivers/video/fbdev/core/fbcon_ccw.c b/drivers/video/fbdev/cor= e/fbcon_ccw.c index 72453a2aaca8..723d9a33067f 100644 --- a/drivers/video/fbdev/core/fbcon_ccw.c +++ b/drivers/video/fbdev/core/fbcon_ccw.c @@ -296,57 +296,26 @@ static void ccw_cursor(struct vc_data *vc, struct fb_= info *info, bool enable, vc->vc_cursor_type !=3D par->p->cursor_shape || par->cursor_state.mask =3D=3D NULL || par->cursor_reset) { - char *tmp, *mask =3D kmalloc_array(w, vc->vc_font.width, - GFP_ATOMIC); - int cur_height, size, i =3D 0; - int width =3D font_glyph_pitch(vc->vc_font.width); + unsigned char *tmp, *mask; =20 - if (!mask) + tmp =3D kmalloc_array(vc->vc_font.height, vc_font_pitch(&vc->vc_font), G= FP_ATOMIC); + if (!tmp) return; + fbcon_fill_cursor_mask(par, vc, tmp); =20 - tmp =3D kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC); - - if (!tmp) { - kfree(mask); + mask =3D kmalloc_array(vc->vc_font.width, w, GFP_ATOMIC); + if (!mask) { + kfree(tmp); return; } + font_glyph_rotate_270(tmp, vc->vc_font.width, vc->vc_font.height, mask); + kfree(tmp); =20 kfree(par->cursor_state.mask); - par->cursor_state.mask =3D mask; + par->cursor_state.mask =3D (const char *)mask; =20 par->p->cursor_shape =3D vc->vc_cursor_type; cursor.set |=3D FB_CUR_SETSHAPE; - - switch (CUR_SIZE(par->p->cursor_shape)) { - case CUR_NONE: - cur_height =3D 0; - break; - case CUR_UNDERLINE: - cur_height =3D (vc->vc_font.height < 10) ? 1 : 2; - break; - case CUR_LOWER_THIRD: - cur_height =3D vc->vc_font.height/3; - break; - case CUR_LOWER_HALF: - cur_height =3D vc->vc_font.height >> 1; - break; - case CUR_TWO_THIRDS: - cur_height =3D (vc->vc_font.height << 1)/3; - break; - case CUR_BLOCK: - default: - cur_height =3D vc->vc_font.height; - break; - } - - size =3D (vc->vc_font.height - cur_height) * width; - while (size--) - tmp[i++] =3D 0; - size =3D cur_height * width; - while (size--) - tmp[i++] =3D 0xff; - font_glyph_rotate_270(tmp, vc->vc_font.width, vc->vc_font.height, mask); - kfree(tmp); } =20 par->cursor_state.enable =3D enable && !use_sw; diff --git a/drivers/video/fbdev/core/fbcon_cw.c b/drivers/video/fbdev/core= /fbcon_cw.c index 5690fc1d7854..732d093d462f 100644 --- a/drivers/video/fbdev/core/fbcon_cw.c +++ b/drivers/video/fbdev/core/fbcon_cw.c @@ -279,57 +279,26 @@ static void cw_cursor(struct vc_data *vc, struct fb_i= nfo *info, bool enable, vc->vc_cursor_type !=3D par->p->cursor_shape || par->cursor_state.mask =3D=3D NULL || par->cursor_reset) { - char *tmp, *mask =3D kmalloc_array(w, vc->vc_font.width, - GFP_ATOMIC); - int cur_height, size, i =3D 0; - int width =3D font_glyph_pitch(vc->vc_font.width); + unsigned char *tmp, *mask; =20 - if (!mask) + tmp =3D kmalloc_array(vc->vc_font.height, vc_font_pitch(&vc->vc_font), G= FP_ATOMIC); + if (!tmp) return; + fbcon_fill_cursor_mask(par, vc, tmp); =20 - tmp =3D kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC); - - if (!tmp) { - kfree(mask); + mask =3D kmalloc_array(vc->vc_font.width, w, GFP_ATOMIC); + if (!mask) { + kfree(tmp); return; } + font_glyph_rotate_90(tmp, vc->vc_font.width, vc->vc_font.height, mask); + kfree(tmp); =20 kfree(par->cursor_state.mask); - par->cursor_state.mask =3D mask; + par->cursor_state.mask =3D (const char *)mask; =20 par->p->cursor_shape =3D vc->vc_cursor_type; cursor.set |=3D FB_CUR_SETSHAPE; - - switch (CUR_SIZE(par->p->cursor_shape)) { - case CUR_NONE: - cur_height =3D 0; - break; - case CUR_UNDERLINE: - cur_height =3D (vc->vc_font.height < 10) ? 1 : 2; - break; - case CUR_LOWER_THIRD: - cur_height =3D vc->vc_font.height/3; - break; - case CUR_LOWER_HALF: - cur_height =3D vc->vc_font.height >> 1; - break; - case CUR_TWO_THIRDS: - cur_height =3D (vc->vc_font.height << 1)/3; - break; - case CUR_BLOCK: - default: - cur_height =3D vc->vc_font.height; - break; - } - - size =3D (vc->vc_font.height - cur_height) * width; - while (size--) - tmp[i++] =3D 0; - size =3D cur_height * width; - while (size--) - tmp[i++] =3D 0xff; - font_glyph_rotate_90(tmp, vc->vc_font.width, vc->vc_font.height, mask); - kfree(tmp); } =20 par->cursor_state.enable =3D enable && !use_sw; diff --git a/drivers/video/fbdev/core/fbcon_ud.c b/drivers/video/fbdev/core= /fbcon_ud.c index f7cd89c42b01..a1981fa4701a 100644 --- a/drivers/video/fbdev/core/fbcon_ud.c +++ b/drivers/video/fbdev/core/fbcon_ud.c @@ -326,50 +326,26 @@ static void ud_cursor(struct vc_data *vc, struct fb_i= nfo *info, bool enable, vc->vc_cursor_type !=3D par->p->cursor_shape || par->cursor_state.mask =3D=3D NULL || par->cursor_reset) { - char *mask =3D kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC); - int cur_height, size, i =3D 0; - u8 msk =3D 0xff; + unsigned char *tmp, *mask; =20 - if (!mask) + tmp =3D kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC); + if (!tmp) return; + fbcon_fill_cursor_mask(par, vc, tmp); + + mask =3D kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC); + if (!mask) { + kfree(tmp); + return; + } + font_glyph_rotate_180(tmp, vc->vc_font.width, vc->vc_font.height, mask); + kfree(tmp); =20 kfree(par->cursor_state.mask); - par->cursor_state.mask =3D mask; + par->cursor_state.mask =3D (const char *)mask; =20 par->p->cursor_shape =3D vc->vc_cursor_type; cursor.set |=3D FB_CUR_SETSHAPE; - - switch (CUR_SIZE(par->p->cursor_shape)) { - case CUR_NONE: - cur_height =3D 0; - break; - case CUR_UNDERLINE: - cur_height =3D (vc->vc_font.height < 10) ? 1 : 2; - break; - case CUR_LOWER_THIRD: - cur_height =3D vc->vc_font.height/3; - break; - case CUR_LOWER_HALF: - cur_height =3D vc->vc_font.height >> 1; - break; - case CUR_TWO_THIRDS: - cur_height =3D (vc->vc_font.height << 1)/3; - break; - case CUR_BLOCK: - default: - cur_height =3D vc->vc_font.height; - break; - } - - size =3D cur_height * w; - - while (size--) - mask[i++] =3D msk; - - size =3D (vc->vc_font.height - cur_height) * w; - - while (size--) - mask[i++] =3D ~msk; } =20 par->cursor_state.enable =3D enable && !use_sw; --=20 2.53.0 From nobody Thu Apr 2 15:41:23 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B16103E9F72 for ; Fri, 27 Mar 2026 13:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616706; cv=none; b=iAtV0rL9CJbktXgcuVdmRuY4HPI7A5WVmryTznqJEbPx7voUoqZBMbo04wX4B+0LY3rfWDBTHkypCLnIAOXRA4aqN5z1fihhoCwVwf+cXjxvSyvmiRbLPSgRjU6yXBVOu3JM53Mu+mcXC6AAKKb/teHQgSAXCqvCOkizNamB5+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774616706; c=relaxed/simple; bh=DS/q87OVT+9erS5Tcvn8vIFJCscEEij4sUfH+johEzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kolDzpmxPYQpY6vmdPSQU8yJyuh2pcVysOKgnCWwrZFqDxVWvu7+E+RmxFPEaUnA+Iy+yRO65Pnv7NnCMgCXeBBX00uhaRhXK34z7mXlAvUovqN0k7ke+0v2djO4zE9fE0B++Oq4bI4812Qbhws4Mf/GXh+us5AY8chrEQfyh2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=TKikD3n6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=42V2IK1l; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=TKikD3n6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=42V2IK1l; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="TKikD3n6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="42V2IK1l"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="TKikD3n6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="42V2IK1l" 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-out2.suse.de (Postfix) with ESMTPS id DEA375BE69; Fri, 27 Mar 2026 13:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616678; 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=s8N0WqiipsboIKRPSmJKTFrwk5c0sveM2dZgxXJLu0I=; b=TKikD3n684ivSUGP+4hweAApPk+H2bl6CqhLJJnI1hQMLDBptxssFRZ30u+jDKcta1TmqV CWx75yeN54TXv85PkpQ2/jZRsPBAjZGamoRjhmLmqxfvQfrKCjDgKV4897FvBok1ILjj+/ j/t3V24MaXDBKvICax5bexqeIHr/yrs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616678; 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=s8N0WqiipsboIKRPSmJKTFrwk5c0sveM2dZgxXJLu0I=; b=42V2IK1lQcc4vOhUI+yq6wYgcC73IlsJytUA3+AEx0WSuADtY3ue0uczefmFU/K6uMvm9X eM/AHdkNUV1O0aBQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774616678; 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=s8N0WqiipsboIKRPSmJKTFrwk5c0sveM2dZgxXJLu0I=; b=TKikD3n684ivSUGP+4hweAApPk+H2bl6CqhLJJnI1hQMLDBptxssFRZ30u+jDKcta1TmqV CWx75yeN54TXv85PkpQ2/jZRsPBAjZGamoRjhmLmqxfvQfrKCjDgKV4897FvBok1ILjj+/ j/t3V24MaXDBKvICax5bexqeIHr/yrs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774616678; 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=s8N0WqiipsboIKRPSmJKTFrwk5c0sveM2dZgxXJLu0I=; b=42V2IK1lQcc4vOhUI+yq6wYgcC73IlsJytUA3+AEx0WSuADtY3ue0uczefmFU/K6uMvm9X eM/AHdkNUV1O0aBQ== 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 9CD2B4A0A2; Fri, 27 Mar 2026 13:04:38 +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 gFAZJWaAxmmweQAAD6G6ig (envelope-from ); Fri, 27 Mar 2026 13:04:38 +0000 From: Thomas Zimmermann To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, simona@ffwll.ch, sam@ravnborg.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Thomas Zimmermann Subject: [PATCH 10/10] fbcon: Put font-rotation state into separate struct Date: Fri, 27 Mar 2026 13:49:43 +0100 Message-ID: <20260327130431.59481-11-tzimmermann@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327130431.59481-1-tzimmermann@suse.de> References: <20260327130431.59481-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_TO(0.00)[gmx.de,linuxfoundation.org,kernel.org,ffwll.ch,ravnborg.org]; RCPT_COUNT_SEVEN(0.00)[10]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmx.de] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Move all temporary state of the font-rotation code into the struct rotated in struct fbcon_par. Protect it with the Kconfig symbol CONFIG_FRAMEBUFFER_CONSOLE_ROTATION. Avoids mixing it up with fbcon's regular state. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 8 ++++++-- drivers/video/fbdev/core/fbcon.h | 12 +++++++---- drivers/video/fbdev/core/fbcon_ccw.c | 8 ++++---- drivers/video/fbdev/core/fbcon_cw.c | 8 ++++---- drivers/video/fbdev/core/fbcon_rotate.c | 27 +++++++++++++------------ drivers/video/fbdev/core/fbcon_ud.c | 10 ++++----- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 345d9aa193f0..00fa5990dfc5 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -787,7 +787,9 @@ static void fbcon_release(struct fb_info *info) kfree(par->cursor_state.mask); kfree(par->cursor_data); kfree(par->cursor_src); - kfree(par->fontbuffer); +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + kfree(par->rotated.buf); +#endif kfree(info->fbcon_par); info->fbcon_par =3D NULL; } @@ -1040,7 +1042,9 @@ static const char *fbcon_startup(void) par =3D info->fbcon_par; par->currcon =3D -1; par->graphics =3D 1; - par->cur_rotate =3D -1; +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + par->rotated.buf_rotate =3D -1; +#endif =20 p->con_rotate =3D initial_rotation; if (p->con_rotate =3D=3D -1) diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fb= con.h index bb0727b70631..5a3866b7ee33 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -80,13 +80,17 @@ struct fbcon_par { int graphics; bool initialized; int rotate; - int cur_rotate; char *cursor_data; - u8 *fontbuffer; - const u8 *fontdata; +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + struct { + font_data_t *fontdata; /* source font */ + u8 *buf; /* rotated glphys */ + size_t bufsize; + int buf_rotate; /* rotation of buf */ + } rotated; +#endif u8 *cursor_src; u32 cursor_size; - size_t fd_size; =20 const struct fbcon_bitops *bitops; }; diff --git a/drivers/video/fbdev/core/fbcon_ccw.c b/drivers/video/fbdev/cor= e/fbcon_ccw.c index 723d9a33067f..33f02d579e02 100644 --- a/drivers/video/fbdev/core/fbcon_ccw.c +++ b/drivers/video/fbdev/core/fbcon_ccw.c @@ -106,7 +106,7 @@ static inline void ccw_putcs_aligned(struct vc_data *vc= , struct fb_info *info, u8 *src; =20 while (cnt--) { - src =3D par->fontbuffer + (scr_readw(s--) & charmask) * cellsize; + src =3D par->rotated.buf + (scr_readw(s--) & charmask) * cellsize; =20 if (attr) { ccw_update_attr(buf, src, attr, vc); @@ -142,7 +142,7 @@ static void ccw_putcs(struct vc_data *vc, struct fb_inf= o *info, u8 *dst, *buf =3D NULL; u32 vyres =3D GETVYRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 image.fg_color =3D fg; @@ -232,14 +232,14 @@ static void ccw_cursor(struct vc_data *vc, struct fb_= info *info, bool enable, char *src; u32 vyres =3D GETVYRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 cursor.set =3D 0; =20 c =3D scr_readw((u16 *) vc->vc_pos); attribute =3D get_attribute(info, c); - src =3D par->fontbuffer + ((c & charmask) * (w * vc->vc_font.width)); + src =3D par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); =20 if (par->cursor_state.image.data !=3D src || par->cursor_reset) { diff --git a/drivers/video/fbdev/core/fbcon_cw.c b/drivers/video/fbdev/core= /fbcon_cw.c index 732d093d462f..bde820967eb9 100644 --- a/drivers/video/fbdev/core/fbcon_cw.c +++ b/drivers/video/fbdev/core/fbcon_cw.c @@ -91,7 +91,7 @@ static inline void cw_putcs_aligned(struct vc_data *vc, s= truct fb_info *info, u8 *src; =20 while (cnt--) { - src =3D par->fontbuffer + (scr_readw(s++) & charmask) * cellsize; + src =3D par->rotated.buf + (scr_readw(s++) & charmask) * cellsize; =20 if (attr) { cw_update_attr(buf, src, attr, vc); @@ -127,7 +127,7 @@ static void cw_putcs(struct vc_data *vc, struct fb_info= *info, u8 *dst, *buf =3D NULL; u32 vxres =3D GETVXRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 image.fg_color =3D fg; @@ -215,14 +215,14 @@ static void cw_cursor(struct vc_data *vc, struct fb_i= nfo *info, bool enable, char *src; u32 vxres =3D GETVXRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 cursor.set =3D 0; =20 c =3D scr_readw((u16 *) vc->vc_pos); attribute =3D get_attribute(info, c); - src =3D par->fontbuffer + ((c & charmask) * (w * vc->vc_font.width)); + src =3D par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); =20 if (par->cursor_state.image.data !=3D src || par->cursor_reset) { diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/= core/fbcon_rotate.c index 74206f5a6e98..6cdbc96eeca6 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -18,34 +18,35 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc) { struct fbcon_par *par =3D info->fbcon_par; - unsigned char *fontbuffer; + unsigned char *buf; int ret; =20 - if (vc->vc_font.data =3D=3D par->fontdata && - par->p->con_rotate =3D=3D par->cur_rotate) + if (par->p->fontdata =3D=3D par->rotated.fontdata && par->rotate =3D=3D p= ar->rotated.buf_rotate) return 0; =20 - par->fontdata =3D vc->vc_font.data; - par->cur_rotate =3D par->p->con_rotate; + par->rotated.fontdata =3D par->p->fontdata; + par->rotated.buf_rotate =3D par->rotate; =20 if (info->fbops->fb_sync) info->fbops->fb_sync(info); =20 - fontbuffer =3D font_data_rotate(par->p->fontdata, vc->vc_font.width, - vc->vc_font.height, vc->vc_font.charcount, - par->rotate, par->fontbuffer, &par->fd_size); - if (IS_ERR(fontbuffer)) { - ret =3D PTR_ERR(fontbuffer); + buf =3D font_data_rotate(par->rotated.fontdata, vc->vc_font.width, + vc->vc_font.height, vc->vc_font.charcount, + par->rotated.buf_rotate, par->rotated.buf, + &par->rotated.bufsize); + if (IS_ERR(buf)) { + ret =3D PTR_ERR(buf); goto err_kfree; } =20 - par->fontbuffer =3D fontbuffer; + par->rotated.buf =3D buf; =20 return 0; =20 err_kfree: - kfree(par->fontbuffer); - par->fontbuffer =3D NULL; /* clear here to avoid output */ + kfree(par->rotated.buf); + par->rotated.buf =3D NULL; /* clear here to avoid output */ + par->rotated.bufsize =3D 0; =20 return ret; } diff --git a/drivers/video/fbdev/core/fbcon_ud.c b/drivers/video/fbdev/core= /fbcon_ud.c index a1981fa4701a..eaf08999e249 100644 --- a/drivers/video/fbdev/core/fbcon_ud.c +++ b/drivers/video/fbdev/core/fbcon_ud.c @@ -92,7 +92,7 @@ static inline void ud_putcs_aligned(struct vc_data *vc, s= truct fb_info *info, u8 *src; =20 while (cnt--) { - src =3D par->fontbuffer + (scr_readw(s--) & charmask) * cellsize; + src =3D par->rotated.buf + (scr_readw(s--) & charmask) * cellsize; =20 if (attr) { ud_update_attr(buf, src, attr, vc); @@ -127,7 +127,7 @@ static inline void ud_putcs_unaligned(struct vc_data *v= c, u8 *src; =20 while (cnt--) { - src =3D par->fontbuffer + (scr_readw(s--) & charmask) * cellsize; + src =3D par->rotated.buf + (scr_readw(s--) & charmask) * cellsize; =20 if (attr) { ud_update_attr(buf, src, attr, vc); @@ -164,7 +164,7 @@ static void ud_putcs(struct vc_data *vc, struct fb_info= *info, u32 vyres =3D GETVYRES(par->p, info); u32 vxres =3D GETVXRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 image.fg_color =3D fg; @@ -262,14 +262,14 @@ static void ud_cursor(struct vc_data *vc, struct fb_i= nfo *info, bool enable, u32 vyres =3D GETVYRES(par->p, info); u32 vxres =3D GETVXRES(par->p, info); =20 - if (!par->fontbuffer) + if (!par->rotated.buf) return; =20 cursor.set =3D 0; =20 c =3D scr_readw((u16 *) vc->vc_pos); attribute =3D get_attribute(info, c); - src =3D par->fontbuffer + ((c & charmask) * (w * vc->vc_font.height)); + src =3D par->rotated.buf + ((c & charmask) * (w * vc->vc_font.height)); =20 if (par->cursor_state.image.data !=3D src || par->cursor_reset) { --=20 2.53.0