Commit a7e50de4 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

tty/vt: consolemap: change refcount only if needed in con_do_clear_unimap()

con_do_clear_unimap() currently decreases and increases refcount of old
dictionary in a back and forth fashion. This makes the code really hard
to follow. Decrease the refcount only if everything went well and we
really allocated a new one and decoupled from the old dictionary.

I sincerelly hope I did not make a mistake in this (ill) logic.
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20220607104946.18710-33-jslaby@suse.czSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d8d0d175
...@@ -535,22 +535,23 @@ static int con_do_clear_unimap(struct vc_data *vc) ...@@ -535,22 +535,23 @@ static int con_do_clear_unimap(struct vc_data *vc)
{ {
struct uni_pagedict *old = *vc->vc_uni_pagedir_loc; struct uni_pagedict *old = *vc->vc_uni_pagedir_loc;
if (!old || --old->refcount) { if (!old || old->refcount > 1) {
struct uni_pagedict *new = kzalloc(sizeof(*new), GFP_KERNEL); struct uni_pagedict *new = kzalloc(sizeof(*new), GFP_KERNEL);
if (!new) { if (!new)
if (old)
old->refcount++;
return -ENOMEM; return -ENOMEM;
}
new->refcount = 1; new->refcount = 1;
*vc->vc_uni_pagedir_loc = new; *vc->vc_uni_pagedir_loc = new;
if (old)
old->refcount--;
} else { } else {
if (old == dflt) if (old == dflt)
dflt = NULL; dflt = NULL;
old->refcount++;
old->sum = 0; old->sum = 0;
con_release_unimap(old); con_release_unimap(old);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment