4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <ti...@suse.de>

commit 8aac7f34369726d1a158788ae8aff3002d5eb528 upstream.

fbcon can deal with vc_hi_font_mask (the upper 256 chars) and adjust
the vc attrs dynamically when vc_hi_font_mask is changed at
fbcon_init().  When the vc_hi_font_mask is set, it remaps the attrs in
the existing console buffer with one bit shift up (for 9 bits), while
it remaps with one bit shift down (for 8 bits) when the value is
cleared.  It works fine as long as the font gets updated after fbcon
was initialized.

However, we hit a bizarre problem when the console is switched to
another fb driver (typically from vesafb or efifb to drmfb).  At
switching to the new fb driver, we temporarily rebind the console to
the dummy console, then rebind to the new driver.  During the
switching, we leave the modified attrs as is.  Thus, the new fbcon
takes over the old buffer as if it were to contain 8 bits chars
(although the attrs are still shifted for 9 bits), and effectively
this results in the yellow color texts instead of the original white
color, as found in the bugzilla entry below.

An easy fix for this is to re-adjust the attrs before leaving the
fbcon at con_deinit callback.  Since the code to adjust the attrs is
already present in the current fbcon code, in this patch, we simply
factor out the relevant code, and call it from fbcon_deinit().

Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1000619
Signed-off-by: Takashi Iwai <ti...@suse.de>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnier...@samsung.com>
Cc: Arnd Bergmann <a...@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 drivers/video/console/fbcon.c |   67 +++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 27 deletions(-)

--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -1168,6 +1168,8 @@ static void fbcon_free_font(struct displ
        p->userfont = 0;
 }
 
+static void set_vc_hi_font(struct vc_data *vc, bool set);
+
 static void fbcon_deinit(struct vc_data *vc)
 {
        struct display *p = &fb_display[vc->vc_num];
@@ -1203,6 +1205,9 @@ finished:
        if (free_font)
                vc->vc_font.data = NULL;
 
+       if (vc->vc_hi_font_mask)
+               set_vc_hi_font(vc, false);
+
        if (!con_is_bound(&fb_con))
                fbcon_exit();
 
@@ -2439,32 +2444,10 @@ static int fbcon_get_font(struct vc_data
        return 0;
 }
 
-static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
-                            const u8 * data, int userfont)
+/* set/clear vc_hi_font_mask and update vc attrs accordingly */
+static void set_vc_hi_font(struct vc_data *vc, bool set)
 {
-       struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
-       struct fbcon_ops *ops = info->fbcon_par;
-       struct display *p = &fb_display[vc->vc_num];
-       int resize;
-       int cnt;
-       char *old_data = NULL;
-
-       if (CON_IS_VISIBLE(vc) && softback_lines)
-               fbcon_set_origin(vc);
-
-       resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
-       if (p->userfont)
-               old_data = vc->vc_font.data;
-       if (userfont)
-               cnt = FNTCHARCNT(data);
-       else
-               cnt = 256;
-       vc->vc_font.data = (void *)(p->fontdata = data);
-       if ((p->userfont = userfont))
-               REFCOUNT(data)++;
-       vc->vc_font.width = w;
-       vc->vc_font.height = h;
-       if (vc->vc_hi_font_mask && cnt == 256) {
+       if (!set) {
                vc->vc_hi_font_mask = 0;
                if (vc->vc_can_do_color) {
                        vc->vc_complement_mask >>= 1;
@@ -2487,7 +2470,7 @@ static int fbcon_do_set_font(struct vc_d
                            ((c & 0xfe00) >> 1) | (c & 0xff);
                        vc->vc_attr >>= 1;
                }
-       } else if (!vc->vc_hi_font_mask && cnt == 512) {
+       } else {
                vc->vc_hi_font_mask = 0x100;
                if (vc->vc_can_do_color) {
                        vc->vc_complement_mask <<= 1;
@@ -2519,8 +2502,38 @@ static int fbcon_do_set_font(struct vc_d
                        } else
                                vc->vc_video_erase_char = c & ~0x100;
                }
-
        }
+}
+
+static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
+                            const u8 * data, int userfont)
+{
+       struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
+       struct fbcon_ops *ops = info->fbcon_par;
+       struct display *p = &fb_display[vc->vc_num];
+       int resize;
+       int cnt;
+       char *old_data = NULL;
+
+       if (CON_IS_VISIBLE(vc) && softback_lines)
+               fbcon_set_origin(vc);
+
+       resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
+       if (p->userfont)
+               old_data = vc->vc_font.data;
+       if (userfont)
+               cnt = FNTCHARCNT(data);
+       else
+               cnt = 256;
+       vc->vc_font.data = (void *)(p->fontdata = data);
+       if ((p->userfont = userfont))
+               REFCOUNT(data)++;
+       vc->vc_font.width = w;
+       vc->vc_font.height = h;
+       if (vc->vc_hi_font_mask && cnt == 256)
+               set_vc_hi_font(vc, false);
+       else if (!vc->vc_hi_font_mask && cnt == 512)
+               set_vc_hi_font(vc, true);
 
        if (resize) {
                int cols, rows;


Reply via email to