]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/fonts: Fix bit position when rotating by 180 degrees
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 28 Apr 2026 08:28:43 +0000 (10:28 +0200)
committerHelge Deller <deller@gmx.de>
Tue, 28 Apr 2026 12:18:51 +0000 (14:18 +0200)
Fix the horizontal bit position when rotating a glyph by 180°. The
original code in rotate_ud() rounded the value in width up to a
multiple of 8, aka the bit pitch, and calculated the rotated pixel
from that value. The new code stores the glyph's pitch in bit_pitch,
but fails to update the rotated pixel's output accordingly. Simply
replacing the variable does this.

The bug can be reproduced by setting a font with an unaligned width,
such as sun12x22, like this:

 setfont sun12x22
 echo 2 > /sys/class/graphics/fbcon/rotate

Without the fix, the font looks distorted.

Fixes: a30e9e6b018f ("lib/fonts: Refactor glyph-rotation helpers")
Closes: https://lore.gitlab.freedesktop.org/drm-ai-reviews/review-patch7-20260407092555.58816-8-tzimmermann@suse.de/
Cc: dri-devel@lists.freedesktop.org
Cc: linux-fbdev@vger.kernel.org
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>
lib/fonts/font_rotate.c

index 065e0fc0667baf764bc2ef33f5b0f28a40d5d57b..275406008823b6194a768646063b6aa49aaa96f4 100644 (file)
@@ -106,7 +106,7 @@ static void __font_glyph_rotate_180(const unsigned char *glyph,
        for (y = 0; y < height; y++) {
                for (x = 0; x < width; x++) {
                        if (font_glyph_test_bit(glyph, x, y, bit_pitch)) {
-                               font_glyph_set_bit(out, width - (1 + x + shift), height - (1 + y),
+                               font_glyph_set_bit(out, bit_pitch - 1 - x - shift, height - 1 - y,
                                                   bit_pitch);
                        }
                }