]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/fonts: Read font size with font_data_size()
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 9 Mar 2026 14:14:50 +0000 (15:14 +0100)
committerHelge Deller <deller@gmx.de>
Mon, 9 Mar 2026 14:47:20 +0000 (15:47 +0100)
Add font_data_size() and update consoles to use it.

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

index 857b85df360c00212f2defbe19ace63e6cd3313a..00ace2940aa0776a82bb07839bd27a6de9d81e5e 100644 (file)
@@ -530,7 +530,7 @@ static int newport_set_font(int unit, const struct console_font *op,
        /* check if font is already used by other console */
        for (i = 0; i < MAX_NR_CONSOLES; i++) {
                if (font_data[i] != FONT_DATA
-                   && FNTSIZE(font_data[i]) == size
+                   && font_data_size(font_data[i]) == size
                    && !memcmp(font_data[i], new_data, size)) {
                        kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
                        /* current font is the same as the new one */
index 8d7840b9ebad947faac0b51e23e5b802aff92e9f..fa8f3e4196de25f277387b5ca9edce27d80c8284 100644 (file)
@@ -2053,7 +2053,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
        struct fb_var_screeninfo var = info->var;
        int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
 
-       if (p->userfont && FNTSIZE(p->fontdata)) {
+       if (p->userfont && font_data_size(p->fontdata)) {
                unsigned int size = vc_font_size(&vc->vc_font);
 
                /*
@@ -2063,7 +2063,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 (!size || size > FNTSIZE(p->fontdata))
+               if (!size || size > font_data_size(p->fontdata))
                        return -EINVAL;
        }
 
@@ -2302,7 +2302,7 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigne
 
        if (font->width <= 8) {
                j = vc->vc_font.height;
-               if (font->charcount * j > FNTSIZE(fontdata))
+               if (font->charcount * j > font_data_size(fontdata))
                        return -EINVAL;
 
                for (i = 0; i < font->charcount; i++) {
@@ -2313,7 +2313,7 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigne
                }
        } else if (font->width <= 16) {
                j = vc->vc_font.height * 2;
-               if (font->charcount * j > FNTSIZE(fontdata))
+               if (font->charcount * j > font_data_size(fontdata))
                        return -EINVAL;
 
                for (i = 0; i < font->charcount; i++) {
@@ -2323,7 +2323,7 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigne
                        fontdata += j;
                }
        } else if (font->width <= 24) {
-               if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
+               if (font->charcount * (vc->vc_font.height * sizeof(u32)) > font_data_size(fontdata))
                        return -EINVAL;
 
                for (i = 0; i < font->charcount; i++) {
@@ -2338,7 +2338,7 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigne
                }
        } else {
                j = vc->vc_font.height * 4;
-               if (font->charcount * j > FNTSIZE(fontdata))
+               if (font->charcount * j > font_data_size(fontdata))
                        return -EINVAL;
 
                for (i = 0; i < font->charcount; i++) {
@@ -2553,7 +2553,7 @@ static int fbcon_set_font(struct vc_data *vc, const struct console_font *font,
                if (fb_display[i].userfont &&
                    fb_display[i].fontdata &&
                    FNTSUM(fb_display[i].fontdata) == csum &&
-                   FNTSIZE(fb_display[i].fontdata) == size &&
+                   font_data_size(fb_display[i].fontdata) == size &&
                    tmp->vc_font.width == w &&
                    !memcmp(fb_display[i].fontdata, new_data, size)) {
                        kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
index 746a0996a018b2b3511c428fbe1fd4abc4a37651..5b8557813c5c703720f8930a9c549d2946d112ae 100644 (file)
@@ -54,6 +54,8 @@ static inline const unsigned char *font_data_buf(font_data_t *fd)
        return (const unsigned char *)fd;
 }
 
+unsigned int font_data_size(font_data_t *fd);
+
 /*
  * Font description
  */
index a7f118b3017191da23debc0ea8c82c0c5682c8c4..8c9a6762061cb13742c0af15f7bbc49be57934b0 100644 (file)
 #endif
 #include <linux/font.h>
 
+/*
+ * Helpers for font_data_t
+ */
+
+/**
+ * font_data_size - Return size of the font data in bytes
+ * @fd: Font data
+ *
+ * Returns:
+ * The number of bytes in the given font data.
+ */
+unsigned int font_data_size(font_data_t *fd)
+{
+       return FNTSIZE(fd);
+}
+EXPORT_SYMBOL_GPL(font_data_size);
+
+/*
+ * Font lookup
+ */
+
 static const struct font_desc *fonts[] = {
 #ifdef CONFIG_FONT_8x8
        &font_vga_8x8,