From 0f2893f0d1acff4bb1677b60c0486adc0075cb99 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 13 May 2014 12:09:27 +0200 Subject: vgacon: Fix & cleanup refcounting The vgacon driver prepares a two element array of uni_pagedir_loc and uses the second item as its own reference counter for sharing the uni_pagedir. And the code assumes blindly that the second item is available if the assigned vc_uni_pagedir isn't the standard one, which might be wrong (although currently it's so). This patch fixes that wrong assumption, and gives a slight cleanup along with it: namely, instead of array, just give the uni_pagedir_loc and a separate refcount variable. It makes the code a bit more understandable at first glance. Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- drivers/video/console/vgacon.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c index 9d8feac6763..9e18770aaba 100644 --- a/drivers/video/console/vgacon.c +++ b/drivers/video/console/vgacon.c @@ -87,7 +87,8 @@ static void vgacon_save_screen(struct vc_data *c); static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, int lines); static void vgacon_invert_region(struct vc_data *c, u16 * p, int count); -static unsigned long vgacon_uni_pagedir[2]; +static unsigned long vgacon_uni_pagedir; +static int vgacon_refcount; /* Description of the hardware situation */ static int vga_init_done __read_mostly; @@ -575,12 +576,12 @@ static void vgacon_init(struct vc_data *c, int init) if (vga_512_chars) c->vc_hi_font_mask = 0x0800; p = *c->vc_uni_pagedir_loc; - if (c->vc_uni_pagedir_loc == &c->vc_uni_pagedir || - !--c->vc_uni_pagedir_loc[1]) + if (c->vc_uni_pagedir_loc != &vgacon_uni_pagedir) { con_free_unimap(c); - c->vc_uni_pagedir_loc = vgacon_uni_pagedir; - vgacon_uni_pagedir[1]++; - if (!vgacon_uni_pagedir[0] && p) + c->vc_uni_pagedir_loc = &vgacon_uni_pagedir; + vgacon_refcount++; + } + if (!vgacon_uni_pagedir && p) con_set_default_unimap(c); /* Only set the default if the user didn't deliberately override it */ @@ -597,7 +598,7 @@ static void vgacon_deinit(struct vc_data *c) vga_set_mem_top(c); } - if (!--vgacon_uni_pagedir[1]) + if (!--vgacon_refcount) con_free_unimap(c); c->vc_uni_pagedir_loc = &c->vc_uni_pagedir; con_set_default_unimap(c); -- cgit v1.2.3-18-g5258 From e4bdab70dd07d8648a1ec3e029239aa86eb836b6 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 13 May 2014 12:09:28 +0200 Subject: console: Use explicit pointer type for vc_uni_pagedir* fields The vc_data.vc_uni_pagedir filed is currently long int, supposedly to be served generically. This, however, leads to lots of cast to pointer, and rather it worsens the readability significantly. Actually, we have now only a single uni_pagedir map implementation, and this won't change likely. So, it'd be much more simple and error-prone to just use the exact pointer for struct uni_pagedir instead of long. Ditto for vc_uni_pagedir_loc. It's a pointer to the uni_pagedir, thus it can be changed similarly to the exact type. Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- drivers/video/console/vgacon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c index 9e18770aaba..f267284b423 100644 --- a/drivers/video/console/vgacon.c +++ b/drivers/video/console/vgacon.c @@ -87,7 +87,7 @@ static void vgacon_save_screen(struct vc_data *c); static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, int lines); static void vgacon_invert_region(struct vc_data *c, u16 * p, int count); -static unsigned long vgacon_uni_pagedir; +static struct uni_pagedir *vgacon_uni_pagedir; static int vgacon_refcount; /* Description of the hardware situation */ @@ -554,7 +554,7 @@ static const char *vgacon_startup(void) static void vgacon_init(struct vc_data *c, int init) { - unsigned long p; + struct uni_pagedir *p; /* * We cannot be loaded as a module, therefore init is always 1, -- cgit v1.2.3-18-g5258