]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vt: Calculate font-buffer size with vc_font_size()
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 9 Mar 2026 14:14:46 +0000 (15:14 +0100)
committerHelge Deller <deller@gmx.de>
Mon, 9 Mar 2026 14:47:20 +0000 (15:47 +0100)
In fbcon, fbcon_resize() computes the size of the font buffer from the
values stored in vc_font. Move these calculations to the dedicated helpers
vc_font_pitch() and vc_font_size().

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/fbcon.c
include/linux/console_struct.h

index 247bb90c08d347cf9d80312c079ee525301d11a4..103e91c8d874bd2c4aefc2040955baf150112745 100644 (file)
@@ -2037,7 +2037,6 @@ static void updatescrollmode(struct fbcon_display *p,
 }
 
 #define PITCH(w) (((w) + 7) >> 3)
-#define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
 
 static int fbcon_resize(struct vc_data *vc, unsigned int width,
                        unsigned int height, bool from_user)
@@ -2049,8 +2048,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
        int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
 
        if (p->userfont && FNTSIZE(vc->vc_font.data)) {
-               int size;
-               int pitch = PITCH(vc->vc_font.width);
+               unsigned int size = vc_font_size(&vc->vc_font);
 
                /*
                 * If user font, ensure that a possible change to user font
@@ -2059,10 +2057,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
                 * charcount can change and cannot be used to determine the
                 * font data allocated size.
                 */
-               if (pitch <= 0)
-                       return -EINVAL;
-               size = CALC_FONTSZ(vc->vc_font.height, pitch, vc->vc_font.charcount);
-               if (size > FNTSIZE(vc->vc_font.data))
+               if (!size || size > FNTSIZE(vc->vc_font.data))
                        return -EINVAL;
        }
 
index ea0cdf4278a3fd04de224a30ae119e16519985b7..771cba16cb542d6b31ac8111ebccc70ae90753f4 100644 (file)
@@ -83,6 +83,34 @@ struct vc_font {
        const unsigned char *data;
 };
 
+/**
+ * vc_font_pitch - Calculates the number of bytes between two adjacent scanlines
+ * @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;
+}
+
 /*
  * Example: vc_data of a console that was scrolled 3 lines down.
  *