]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
fbcon: Fill cursor mask in helper function
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 7 Apr 2026 09:23:20 +0000 (11:23 +0200)
committerHelge Deller <deller@gmx.de>
Tue, 7 Apr 2026 15:38:07 +0000 (17:38 +0200)
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.

v2:
- fix sparse truncated-bits warning

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/bitblit.c
drivers/video/fbdev/core/fbcon.c
drivers/video/fbdev/core/fbcon.h
drivers/video/fbdev/core/fbcon_ccw.c
drivers/video/fbdev/core/fbcon_cw.c
drivers/video/fbdev/core/fbcon_ud.c

index 7478accea8ecf0770e8eb2113779f82f8ae30e9b..65681dcc5930dcb6cee0285a60f81bcad6da43af 100644 (file)
@@ -329,46 +329,17 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
            vc->vc_cursor_type != par->p->cursor_shape ||
            par->cursor_state.mask == NULL ||
            par->cursor_reset) {
-               char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
-               int cur_height, size, i = 0;
-               u8 msk = 0xff;
+               unsigned char *mask = kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC);
 
                if (!mask)
                        return;
+               fbcon_fill_cursor_mask(par, vc, mask);
 
                kfree(par->cursor_state.mask);
-               par->cursor_state.mask = mask;
+               par->cursor_state.mask = (const char *)mask;
 
                par->p->cursor_shape = vc->vc_cursor_type;
                cursor.set |= FB_CUR_SETSHAPE;
-
-               switch (CUR_SIZE(par->p->cursor_shape)) {
-               case CUR_NONE:
-                       cur_height = 0;
-                       break;
-               case CUR_UNDERLINE:
-                       cur_height = (vc->vc_font.height < 10) ? 1 : 2;
-                       break;
-               case CUR_LOWER_THIRD:
-                       cur_height = vc->vc_font.height/3;
-                       break;
-               case CUR_LOWER_HALF:
-                       cur_height = vc->vc_font.height >> 1;
-                       break;
-               case CUR_TWO_THIRDS:
-                       cur_height = (vc->vc_font.height << 1)/3;
-                       break;
-               case CUR_BLOCK:
-               default:
-                       cur_height = vc->vc_font.height;
-                       break;
-               }
-               size = (vc->vc_font.height - cur_height) * w;
-               while (size--)
-                       mask[i++] = ~msk;
-               size = cur_height * w;
-               while (size--)
-                       mask[i++] = msk;
        }
 
        par->cursor_state.enable = enable && !use_sw;
index 8641b0b3edc4cfa80c474d4e5291f4aad78debd8..ff4c69e971f8cc19d77a0585d7df173da3a35923 100644 (file)
@@ -446,6 +446,46 @@ static void fbcon_del_cursor_work(struct fb_info *info)
        cancel_delayed_work_sync(&par->cursor_work);
 }
 
+void fbcon_fill_cursor_mask(struct fbcon_par *par, struct vc_data *vc, unsigned char *mask)
+{
+       static const unsigned int pattern = 0xffffffff;
+       unsigned int pitch = vc_font_pitch(&vc->vc_font);
+       unsigned int cur_height, size;
+
+       switch (CUR_SIZE(vc->vc_cursor_type)) {
+       case CUR_NONE:
+               cur_height = 0;
+               break;
+       case CUR_UNDERLINE:
+               if (vc->vc_font.height < 10)
+                       cur_height = 1;
+               else
+                       cur_height = 2;
+               break;
+       case CUR_LOWER_THIRD:
+               cur_height = vc->vc_font.height / 3;
+               break;
+       case CUR_LOWER_HALF:
+               cur_height = vc->vc_font.height / 2;
+               break;
+       case CUR_TWO_THIRDS:
+               cur_height = (vc->vc_font.height * 2) / 3;
+               break;
+       case CUR_BLOCK:
+       default:
+               cur_height = vc->vc_font.height;
+               break;
+       }
+
+       size = (vc->vc_font.height - cur_height) * pitch;
+       while (size--)
+               *mask++ = (unsigned char)~pattern;
+
+       size = cur_height * pitch;
+       while (size--)
+               *mask++ = (unsigned char)pattern;
+}
+
 #ifndef MODULE
 static int __init fb_console_setup(char *this_opt)
 {
index 1793f34a6c844beb5ed8a44e8eb7f9f1c131dede..bb0727b706312cd1346c673b6ae256e036b6e49c 100644 (file)
@@ -192,6 +192,8 @@ extern void fbcon_set_tileops(struct vc_data *vc, struct 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);
 
+void fbcon_fill_cursor_mask(struct fbcon_par *par, struct vc_data *vc, unsigned char *mask);
+
 #define FBCON_ATTRIBUTE_UNDERLINE 1
 #define FBCON_ATTRIBUTE_REVERSE   2
 #define FBCON_ATTRIBUTE_BOLD      4
index 72453a2aaca87352f80c2c0e06047b960d551556..723d9a33067f315ec547460fecf10e5697b60c49 100644 (file)
@@ -296,57 +296,26 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
            vc->vc_cursor_type != par->p->cursor_shape ||
            par->cursor_state.mask == NULL ||
            par->cursor_reset) {
-               char *tmp, *mask = kmalloc_array(w, vc->vc_font.width,
-                                                GFP_ATOMIC);
-               int cur_height, size, i = 0;
-               int width = font_glyph_pitch(vc->vc_font.width);
+               unsigned char *tmp, *mask;
 
-               if (!mask)
+               tmp = kmalloc_array(vc->vc_font.height, vc_font_pitch(&vc->vc_font), GFP_ATOMIC);
+               if (!tmp)
                        return;
+               fbcon_fill_cursor_mask(par, vc, tmp);
 
-               tmp = kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC);
-
-               if (!tmp) {
-                       kfree(mask);
+               mask = 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);
 
                kfree(par->cursor_state.mask);
-               par->cursor_state.mask = mask;
+               par->cursor_state.mask = (const char *)mask;
 
                par->p->cursor_shape = vc->vc_cursor_type;
                cursor.set |= FB_CUR_SETSHAPE;
-
-               switch (CUR_SIZE(par->p->cursor_shape)) {
-               case CUR_NONE:
-                       cur_height = 0;
-                       break;
-               case CUR_UNDERLINE:
-                       cur_height = (vc->vc_font.height < 10) ? 1 : 2;
-                       break;
-               case CUR_LOWER_THIRD:
-                       cur_height = vc->vc_font.height/3;
-                       break;
-               case CUR_LOWER_HALF:
-                       cur_height = vc->vc_font.height >> 1;
-                       break;
-               case CUR_TWO_THIRDS:
-                       cur_height = (vc->vc_font.height << 1)/3;
-                       break;
-               case CUR_BLOCK:
-               default:
-                       cur_height = vc->vc_font.height;
-                       break;
-               }
-
-               size = (vc->vc_font.height - cur_height) * width;
-               while (size--)
-                       tmp[i++] = 0;
-               size = cur_height * width;
-               while (size--)
-                       tmp[i++] = 0xff;
-               font_glyph_rotate_270(tmp, vc->vc_font.width, vc->vc_font.height, mask);
-               kfree(tmp);
        }
 
        par->cursor_state.enable = enable && !use_sw;
index 5690fc1d78547180a548f426c837cb616c930929..732d093d462fa39509389db596121df549680e02 100644 (file)
@@ -279,57 +279,26 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
            vc->vc_cursor_type != par->p->cursor_shape ||
            par->cursor_state.mask == NULL ||
            par->cursor_reset) {
-               char *tmp, *mask = kmalloc_array(w, vc->vc_font.width,
-                                                GFP_ATOMIC);
-               int cur_height, size, i = 0;
-               int width = font_glyph_pitch(vc->vc_font.width);
+               unsigned char *tmp, *mask;
 
-               if (!mask)
+               tmp = kmalloc_array(vc->vc_font.height, vc_font_pitch(&vc->vc_font), GFP_ATOMIC);
+               if (!tmp)
                        return;
+               fbcon_fill_cursor_mask(par, vc, tmp);
 
-               tmp = kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC);
-
-               if (!tmp) {
-                       kfree(mask);
+               mask = 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);
 
                kfree(par->cursor_state.mask);
-               par->cursor_state.mask = mask;
+               par->cursor_state.mask = (const char *)mask;
 
                par->p->cursor_shape = vc->vc_cursor_type;
                cursor.set |= FB_CUR_SETSHAPE;
-
-               switch (CUR_SIZE(par->p->cursor_shape)) {
-               case CUR_NONE:
-                       cur_height = 0;
-                       break;
-               case CUR_UNDERLINE:
-                       cur_height = (vc->vc_font.height < 10) ? 1 : 2;
-                       break;
-               case CUR_LOWER_THIRD:
-                       cur_height = vc->vc_font.height/3;
-                       break;
-               case CUR_LOWER_HALF:
-                       cur_height = vc->vc_font.height >> 1;
-                       break;
-               case CUR_TWO_THIRDS:
-                       cur_height = (vc->vc_font.height << 1)/3;
-                       break;
-               case CUR_BLOCK:
-               default:
-                       cur_height = vc->vc_font.height;
-                       break;
-               }
-
-               size = (vc->vc_font.height - cur_height) * width;
-               while (size--)
-                       tmp[i++] = 0;
-               size = cur_height * width;
-               while (size--)
-                       tmp[i++] = 0xff;
-               font_glyph_rotate_90(tmp, vc->vc_font.width, vc->vc_font.height, mask);
-               kfree(tmp);
        }
 
        par->cursor_state.enable = enable && !use_sw;
index f7cd89c42b01c58afc2444bffa05f8ae122f638a..a1981fa4701a26cc8f4919935b5e8f24854439da 100644 (file)
@@ -326,50 +326,26 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
            vc->vc_cursor_type != par->p->cursor_shape ||
            par->cursor_state.mask == NULL ||
            par->cursor_reset) {
-               char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
-               int cur_height, size, i = 0;
-               u8 msk = 0xff;
+               unsigned char *tmp, *mask;
 
-               if (!mask)
+               tmp = kmalloc_array(vc->vc_font.height, w, GFP_ATOMIC);
+               if (!tmp)
                        return;
+               fbcon_fill_cursor_mask(par, vc, tmp);
+
+               mask = 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);
 
                kfree(par->cursor_state.mask);
-               par->cursor_state.mask = mask;
+               par->cursor_state.mask = (const char *)mask;
 
                par->p->cursor_shape = vc->vc_cursor_type;
                cursor.set |= FB_CUR_SETSHAPE;
-
-               switch (CUR_SIZE(par->p->cursor_shape)) {
-               case CUR_NONE:
-                       cur_height = 0;
-                       break;
-               case CUR_UNDERLINE:
-                       cur_height = (vc->vc_font.height < 10) ? 1 : 2;
-                       break;
-               case CUR_LOWER_THIRD:
-                       cur_height = vc->vc_font.height/3;
-                       break;
-               case CUR_LOWER_HALF:
-                       cur_height = vc->vc_font.height >> 1;
-                       break;
-               case CUR_TWO_THIRDS:
-                       cur_height = (vc->vc_font.height << 1)/3;
-                       break;
-               case CUR_BLOCK:
-               default:
-                       cur_height = vc->vc_font.height;
-                       break;
-               }
-
-               size = cur_height * w;
-
-               while (size--)
-                       mask[i++] = msk;
-
-               size = (vc->vc_font.height - cur_height) * w;
-
-               while (size--)
-                       mask[i++] = ~msk;
        }
 
        par->cursor_state.enable = enable && !use_sw;