aboutsummaryrefslogtreecommitdiff
path: root/drivers/tty/vt
diff options
context:
space:
mode:
authorJiri Slaby2022-06-07 12:49:43 +0200
committerGreg Kroah-Hartman2022-06-10 13:37:03 +0200
commita7e50de460d7d9230dc065c9d2f1a1b1669c675c (patch)
treee53c9b8b96c196850ca65c06396db105dc7d09ab /drivers/tty/vt
parentd8d0d1758c7d5ef37066f1122eb236d47b2948a9 (diff)
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: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20220607104946.18710-33-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r--drivers/tty/vt/consolemap.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 01b7e49f1f91..4d8efe74315c 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -535,22 +535,23 @@ static int con_do_clear_unimap(struct vc_data *vc)
{
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);
- if (!new) {
- if (old)
- old->refcount++;
+ if (!new)
return -ENOMEM;
- }
+
new->refcount = 1;
*vc->vc_uni_pagedir_loc = new;
+
+ if (old)
+ old->refcount--;
} else {
if (old == dflt)
dflt = NULL;
- old->refcount++;
old->sum = 0;
con_release_unimap(old);
}
+
return 0;
}