From: Thomas Zimmermann <tzimmermann@suse.de>
To: deller@gmx.de, simona@ffwll.ch
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
sashiko-reviews@lists.linux.dev,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH v2 4/6] fbcon: Refactor size calculation for cursor buffers
Date: Fri, 20 Nov 2026 12:49:57 +0100 [thread overview]
Message-ID: <20261120115215.52092-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20261120115215.52092-1-tzimmermann@suse.de>
Replace open-coded size calculation for cursor glyph buffers with
font helpers. Use it for glyph lookup and buffer allocation.
Treat glyph width as bits per scanline instead of bytes. This is
consistent with font helpers.
Note that with screen rotation enabled, width and height swap places
for CW and CCW implementations.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/video/fbdev/core/bitblit.c | 9 ++++++---
drivers/video/fbdev/core/fbcon_ccw.c | 10 ++++++----
drivers/video/fbdev/core/fbcon_cw.c | 10 ++++++----
drivers/video/fbdev/core/fbcon_ud.c | 10 ++++++----
4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
index 5cdd70f32c28..1cbfbe50bebf 100644
--- a/drivers/video/fbdev/core/bitblit.c
+++ b/drivers/video/fbdev/core/bitblit.c
@@ -268,7 +268,10 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
struct fb_cursor cursor;
struct fbcon_par *par = info->fbcon_par;
unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
- int w = DIV_ROUND_UP(vc->vc_font.width, 8), c;
+ int width = vc->vc_font.width;
+ int vpitch = vc->vc_font.height;
+ int cellsize = font_glyph_size(width, vpitch);
+ int c;
int y = real_y(par->p, vc->state.y);
int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
int err = 1;
@@ -286,7 +289,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
/* Clamp to font size, same as bit_putcs_aligned() */
if (c >= vc->vc_font.charcount)
c = 0;
- src = vc->vc_font.data + (c * (w * vc->vc_font.height));
+ src = vc->vc_font.data + (c * cellsize);
if (par->cursor_state.image.data != (const char *)src ||
par->cursor_reset) {
@@ -297,7 +300,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (attribute) {
unsigned char *dst;
- dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
+ dst = kmalloc(cellsize, GFP_ATOMIC);
if (!dst)
return;
kfree(par->cursor_data);
diff --git a/drivers/video/fbdev/core/fbcon_ccw.c b/drivers/video/fbdev/core/fbcon_ccw.c
index de4a58d3385e..589291caed32 100644
--- a/drivers/video/fbdev/core/fbcon_ccw.c
+++ b/drivers/video/fbdev/core/fbcon_ccw.c
@@ -226,7 +226,9 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
struct fb_cursor cursor;
struct fbcon_par *par = info->fbcon_par;
unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
- int w = font_glyph_pitch(vc->vc_font.height);
+ int width = vc->vc_font.height;
+ int vpitch = vc->vc_font.width;
+ int cellsize = font_glyph_size(width, vpitch);
int c;
int y = real_y(par->p, vc->state.y);
int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
@@ -241,7 +243,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
c = scr_readw((u16 *) vc->vc_pos);
attribute = get_attribute(info, c);
- src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width));
+ src = par->rotated.buf + ((c & charmask) * cellsize);
if (par->cursor_state.image.data != (const char *)src ||
par->cursor_reset) {
@@ -252,7 +254,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (attribute) {
unsigned char *dst;
- dst = kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC);
+ dst = kmalloc(cellsize, GFP_ATOMIC);
if (!dst)
return;
kfree(par->cursor_data);
@@ -304,7 +306,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (!tmp)
return;
- mask = kmalloc_array(vc->vc_font.width, w, GFP_ATOMIC);
+ mask = kmalloc(cellsize, GFP_ATOMIC);
if (!mask) {
kfree(tmp);
return;
diff --git a/drivers/video/fbdev/core/fbcon_cw.c b/drivers/video/fbdev/core/fbcon_cw.c
index 4e82199082f1..87e9dd666953 100644
--- a/drivers/video/fbdev/core/fbcon_cw.c
+++ b/drivers/video/fbdev/core/fbcon_cw.c
@@ -209,7 +209,9 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
struct fb_cursor cursor;
struct fbcon_par *par = info->fbcon_par;
unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
- int w = font_glyph_pitch(vc->vc_font.height);
+ int width = vc->vc_font.height;
+ int vpitch = vc->vc_font.width;
+ int cellsize = font_glyph_size(width, vpitch);
int c;
int y = real_y(par->p, vc->state.y);
int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
@@ -224,7 +226,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
c = scr_readw((u16 *) vc->vc_pos);
attribute = get_attribute(info, c);
- src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width));
+ src = par->rotated.buf + ((c & charmask) * (cellsize));
if (par->cursor_state.image.data != (const char *)src ||
par->cursor_reset) {
@@ -235,7 +237,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (attribute) {
unsigned char *dst;
- dst = kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC);
+ dst = kmalloc(cellsize, GFP_ATOMIC);
if (!dst)
return;
kfree(par->cursor_data);
@@ -287,7 +289,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (!tmp)
return;
- mask = kmalloc_array(vc->vc_font.width, w, GFP_ATOMIC);
+ mask = kmalloc(cellsize, GFP_ATOMIC);
if (!mask) {
kfree(tmp);
return;
diff --git a/drivers/video/fbdev/core/fbcon_ud.c b/drivers/video/fbdev/core/fbcon_ud.c
index dc48e19513a1..a610af1023de 100644
--- a/drivers/video/fbdev/core/fbcon_ud.c
+++ b/drivers/video/fbdev/core/fbcon_ud.c
@@ -255,7 +255,9 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
struct fb_cursor cursor;
struct fbcon_par *par = info->fbcon_par;
unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
- int w = font_glyph_pitch(vc->vc_font.width);
+ int width = vc->vc_font.width;
+ int vpitch = vc->vc_font.height;
+ int cellsize = font_glyph_size(width, vpitch);
int c;
int y = real_y(par->p, vc->state.y);
int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
@@ -271,7 +273,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
c = scr_readw((u16 *) vc->vc_pos);
attribute = get_attribute(info, c);
- src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.height));
+ src = par->rotated.buf + ((c & charmask) * cellsize);
if (par->cursor_state.image.data != (const char *)src ||
par->cursor_reset) {
@@ -282,7 +284,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (attribute) {
unsigned char *dst;
- dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
+ dst = kmalloc(cellsize, GFP_ATOMIC);
if (!dst)
return;
kfree(par->cursor_data);
@@ -334,7 +336,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
if (!tmp)
return;
- mask = kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC);
+ mask = kmalloc(cellsize, GFP_ATOMIC);
if (!mask) {
kfree(tmp);
return;
--
2.56.0
next prev parent reply other threads:[~2026-11-20 11:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:49 [PATCH v2 0/6] fbcon: Clean up glyph handling on redraws Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 1/6] fbcon: Use unsigned char for glyph data Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 2/6] lib/fonts: Provide internal helpers for allocating font_data_t Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 3/6] lib/fonts, fbcon: Use font_data_t for rotated fonts Thomas Zimmermann
2026-11-20 12:01 ` sashiko-bot
2026-11-20 11:49 ` Thomas Zimmermann [this message]
2026-11-20 11:49 ` [PATCH v2 5/6] fbcon: Look up glyphs using the font interface Thomas Zimmermann
2026-11-20 12:22 ` sashiko-bot
2026-11-20 11:49 ` [PATCH v2 6/6] fbcon: Handle characters with no glyph defined in a consistent way Thomas Zimmermann
2026-11-20 12:28 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120115215.52092-5-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.