linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 17/36] tty/vt: consolemap: introduce enum translation_map and use it
Date: Tue,  7 Jun 2022 12:49:27 +0200	[thread overview]
Message-ID: <20220607104946.18710-17-jslaby@suse.cz> (raw)
In-Reply-To: <20220607104946.18710-1-jslaby@suse.cz>

Again, instead of magic constants in the code, declare an enum and be a
little bit more explicit. Both in the translations definition and in the
loops etc.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/consolemap.c | 39 +++++++++++++++++++------------------
 include/linux/consolemap.h  | 18 +++++++++++------
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 92b5dddb00d9..80536687acef 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -38,7 +38,7 @@
 
 static unsigned short translations[][256] = {
   /* 8-bit Latin-1 mapped to Unicode -- trivial mapping */
-  {
+  [LAT1_MAP] = {
     0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
     0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
     0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
@@ -71,9 +71,9 @@ static unsigned short translations[][256] = {
     0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
     0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
     0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
-  }, 
+  },
   /* VT100 graphics mapped to Unicode */
-  {
+  [GRAF_MAP] = {
     0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
     0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
     0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
@@ -108,8 +108,8 @@ static unsigned short translations[][256] = {
     0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
   },
   /* IBM Codepage 437 mapped to Unicode */
-  {
-    0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 
+  [IBMPC_MAP] = {
+    0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
     0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,
     0x25b6, 0x25c0, 0x2195, 0x203c, 0x00b6, 0x00a7, 0x25ac, 0x21a8,
     0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc,
@@ -141,9 +141,9 @@ static unsigned short translations[][256] = {
     0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,
     0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248,
     0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0
-  }, 
+  },
   /* User mapping -- default to codes for direct font mapping */
-  {
+  [USER_MAP] = {
     0xf000, 0xf001, 0xf002, 0xf003, 0xf004, 0xf005, 0xf006, 0xf007,
     0xf008, 0xf009, 0xf00a, 0xf00b, 0xf00c, 0xf00d, 0xf00e, 0xf00f,
     0xf010, 0xf011, 0xf012, 0xf013, 0xf014, 0xf015, 0xf016, 0xf017,
@@ -184,7 +184,7 @@ static unsigned short translations[][256] = {
 
 #define MAX_GLYPH 512		/* Max possible glyph value */
 
-static int inv_translate[MAX_NR_CONSOLES];
+static enum translation_map inv_translate[MAX_NR_CONSOLES];
 
 #define UNI_DIRS	32U
 #define UNI_DIR_ROWS	32U
@@ -208,24 +208,25 @@ struct uni_pagedict {
 	u16		**uni_pgdir[UNI_DIRS];
 	unsigned long	refcount;
 	unsigned long	sum;
-	unsigned char	*inverse_translations[4];
+	unsigned char	*inverse_translations[LAST_MAP + 1];
 	u16		*inverse_trans_unicode;
 };
 
 static struct uni_pagedict *dflt;
 
-static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *p, int i)
+static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *p,
+	       enum translation_map m)
 {
 	int j, glyph;
-	unsigned short *t = translations[i];
+	unsigned short *t = translations[m];
 	unsigned char *q;
 	
 	if (!p)
 		return;
-	q = p->inverse_translations[i];
+	q = p->inverse_translations[m];
 
 	if (!q) {
-		q = p->inverse_translations[i] = kmalloc(MAX_GLYPH, GFP_KERNEL);
+		q = p->inverse_translations[m] = kmalloc(MAX_GLYPH, GFP_KERNEL);
 		if (!q)
 			return;
 	}
@@ -276,7 +277,7 @@ static void set_inverse_trans_unicode(struct vc_data *conp,
 	}
 }
 
-unsigned short *set_translate(int m, struct vc_data *vc)
+unsigned short *set_translate(enum translation_map m, struct vc_data *vc)
 {
 	inv_translate[vc->vc_num] = m;
 	return translations[m];
@@ -292,7 +293,7 @@ unsigned short *set_translate(int m, struct vc_data *vc)
 u16 inverse_translate(const struct vc_data *conp, u16 glyph, bool use_unicode)
 {
 	struct uni_pagedict *p;
-	int m;
+	enum translation_map m;
 
 	if (glyph >= MAX_GLYPH)
 		return 0;
@@ -669,8 +670,8 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
 	if (con_unify_unimap(vc, p))
 		goto out_unlock;
 
-	for (i = 0; i <= 3; i++)
-		set_inverse_transl(vc, p, i); /* Update inverse translations */
+	for (enum translation_map m = FIRST_MAP; m <= LAST_MAP; m++)
+		set_inverse_transl(vc, p, m); /* Update inverse translations */
 	set_inverse_trans_unicode(vc, p);
 
 out_unlock:
@@ -731,8 +732,8 @@ int con_set_default_unimap(struct vc_data *vc)
 		return err;
 	}
 
-	for (i = 0; i <= 3; i++)
-		set_inverse_transl(vc, p, i);	/* Update all inverse translations */
+	for (enum translation_map m = FIRST_MAP; m <= LAST_MAP; m++)
+		set_inverse_transl(vc, p, m);	/* Update all inverse translations */
 	set_inverse_trans_unicode(vc, p);
 	dflt = p;
 	return err;
diff --git a/include/linux/consolemap.h b/include/linux/consolemap.h
index 1ff2bf55eb85..c35db4896c37 100644
--- a/include/linux/consolemap.h
+++ b/include/linux/consolemap.h
@@ -7,10 +7,15 @@
 #ifndef __LINUX_CONSOLEMAP_H__
 #define __LINUX_CONSOLEMAP_H__
 
-#define LAT1_MAP 0
-#define GRAF_MAP 1
-#define IBMPC_MAP 2
-#define USER_MAP 3
+enum translation_map {
+	LAT1_MAP,
+	GRAF_MAP,
+	IBMPC_MAP,
+	USER_MAP,
+
+	FIRST_MAP = LAT1_MAP,
+	LAST_MAP = USER_MAP,
+};
 
 #include <linux/types.h>
 
@@ -18,7 +23,7 @@ struct vc_data;
 
 #ifdef CONFIG_CONSOLE_TRANSLATIONS
 u16 inverse_translate(const struct vc_data *conp, u16 glyph, bool use_unicode);
-unsigned short *set_translate(int m, struct vc_data *vc);
+unsigned short *set_translate(enum translation_map m, struct vc_data *vc);
 int conv_uni_to_pc(struct vc_data *conp, long ucs);
 u32 conv_8bit_to_uni(unsigned char c);
 int conv_uni_to_8bit(u32 uni);
@@ -30,7 +35,8 @@ static inline u16 inverse_translate(const struct vc_data *conp, u16 glyph,
 	return glyph;
 }
 
-static inline unsigned short *set_translate(int m, struct vc_data *vc)
+static inline unsigned short *set_translate(enum translation_map m,
+		struct vc_data *vc)
 {
 	return NULL;
 }
-- 
2.36.1


  parent reply	other threads:[~2022-06-07 10:53 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 10:49 [PATCH 01/36] tty/vt: consolemap: use ARRAY_SIZE() Jiri Slaby
2022-06-07 10:49 ` [PATCH 02/36] tty/vt: consolemap: rename and document struct uni_pagedir Jiri Slaby
2022-06-07 12:36   ` Ilpo Järvinen
2022-06-08  5:42     ` Jiri Slaby
2022-06-07 10:49 ` [PATCH 03/36] tty/vt: consolemap: define UNI_* macros for constants Jiri Slaby
2022-06-07 13:21   ` Ilpo Järvinen
2022-06-08  6:55     ` Jiri Slaby
2022-06-08  9:54       ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 04/36] tty/vt: consolemap: decrypt inverse_translate() Jiri Slaby
2022-06-07 12:54   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 05/36] tty/vt: consolemap: remove extern from function decls Jiri Slaby
2022-06-07 13:33   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 06/36] tty/vt: consolemap: convert macros to static inlines Jiri Slaby
2022-06-07 13:31   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 07/36] tty/vt: consolemap: make parameters of inverse_translate() saner Jiri Slaby
2022-06-07 13:32   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 08/36] tty/vt: consolemap: one line = one statement Jiri Slaby
2022-06-07 13:35   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 09/36] tty/vt: consolemap: use | for binary addition Jiri Slaby
2022-06-07 13:36   ` Ilpo Järvinen
2022-06-07 13:40     ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 10/36] tty/vt: consolemap: introduce UNI_*() macros Jiri Slaby
2022-06-07 13:47   ` Ilpo Järvinen
2022-06-08  6:59     ` Jiri Slaby
2022-06-08  7:30       ` Jiri Slaby
2022-06-08  8:02         ` Ilpo Järvinen
2022-06-08  8:18           ` Jiri Slaby
2022-06-07 10:49 ` [PATCH 11/36] tty/vt: consolemap: zero uni_pgdir using kcalloc() Jiri Slaby
2022-06-07 13:51   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 12/36] tty/vt: consolemap: use sizeof(*pointer) instead of sizeof(type) Jiri Slaby
2022-06-07 14:00   ` Ilpo Järvinen
2022-06-07 18:13     ` Jiri Slaby
2022-06-08  7:23       ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 13/36] tty/vt: consolemap: make con_set_unimap() more readable Jiri Slaby
2022-06-07 14:06   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 14/36] tty/vt: consolemap: make con_get_unimap() " Jiri Slaby
2022-06-07 14:11   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 15/36] tty/vt: consolemap: make p1 increment less confusing in con_get_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 16/36] tty/vt: consolemap: check put_user() " Jiri Slaby
2022-06-07 14:19   ` Ilpo Järvinen
2022-06-08  7:40     ` Jiri Slaby
2022-06-08  8:13       ` Ilpo Järvinen
2022-06-08 10:38       ` Andy Shevchenko
2022-06-08 10:43         ` Greg Kroah-Hartman
2022-06-08  8:02   ` David Laight
2022-06-08  8:11     ` Jiri Slaby
2022-06-08  8:13       ` Jiri Slaby
2022-06-09  8:51       ` Jiri Slaby
2022-06-07 10:49 ` Jiri Slaby [this message]
2022-06-07 10:49 ` [PATCH 18/36] tty/vt: consolemap: remove glyph < 0 check from set_inverse_trans_unicode() Jiri Slaby
2022-06-07 10:49 ` [PATCH 19/36] tty/vt: consolemap: extract dict unsharing to con_unshare_unimap() Jiri Slaby
2022-06-07 14:30   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 20/36] tty/vt: consolemap: saner variable names in set_inverse_trans_unicode() Jiri Slaby
2022-06-07 14:34   ` Ilpo Järvinen
2022-06-07 10:49 ` [PATCH 21/36] tty/vt: consolemap: saner variable names in conv_uni_to_pc() Jiri Slaby
2022-06-07 10:49 ` [PATCH 22/36] tty/vt: consolemap: saner variable names in con_insert_unipair() Jiri Slaby
2022-06-07 10:49 ` [PATCH 23/36] tty/vt: consolemap: saner variable names in con_unify_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 24/36] tty/vt: consolemap: saner variable names in con_do_clear_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 25/36] tty/vt: consolemap: saner variable names in con_unshare_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 26/36] tty/vt: consolemap: saner variable names in con_release_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 27/36] tty/vt: consolemap: saner variable names in con_copy_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 28/36] tty/vt: consolemap: saner variable names in con_get_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 29/36] tty/vt: consolemap: saner variable names in con_set_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 30/36] tty/vt: consolemap: saner variable names in con_set_default_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 31/36] tty/vt: consolemap: make conv_uni_to_pc() more readable Jiri Slaby
2022-06-07 10:49 ` [PATCH 32/36] tty/vt: consolemap: remove superfluous whitespace Jiri Slaby
2022-06-07 10:49 ` [PATCH 33/36] tty/vt: consolemap: change refcount only if needed in con_do_clear_unimap() Jiri Slaby
2022-06-07 15:31   ` Ilpo Järvinen
2022-06-08  7:44     ` Jiri Slaby
2022-06-07 10:49 ` [PATCH 34/36] tty/vt: consolemap: extract con_allocate_new() from con_do_clear_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 35/36] tty/vt: consolemap: use con_allocate_new() in con_unshare_unimap() Jiri Slaby
2022-06-07 10:49 ` [PATCH 36/36] tty/vt: consolemap: walk the buffer only once in con_set_trans_old() Jiri Slaby
2022-06-07 16:25   ` Ilpo Järvinen
2022-06-07 12:36 ` [PATCH 01/36] tty/vt: consolemap: use ARRAY_SIZE() Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220607104946.18710-17-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).