[PATCH 4/6] fbcon: Refactor size calculation for cursor buffers
flat view
DORMANTno replies
From: Thomas Zimmermann <tzimmermann@suse.de>
Date: 2026-10-27 13:37:24
Also in:
dri-devel, sashiko-reviews
Subsystem:
framebuffer console, framebuffer core, framebuffer layer, the rest · Maintainers:
Helge Deller, Thomas Zimmermann, Simona Vetter, Linus Torvalds
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 df3fdaf392a6..65dbdb666ae2 100644
--- a/drivers/video/fbdev/core/bitblit.c
+++ b/drivers/video/fbdev/core/bitblit.c@@ -248,7 +248,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;
@@ -266,7 +269,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) {
@@ -277,7 +280,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