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 03/36] tty/vt: consolemap: define UNI_* macros for constants
Date: Tue, 7 Jun 2022 12:49:13 +0200 [thread overview]
Message-ID: <20220607104946.18710-3-jslaby@suse.cz> (raw)
In-Reply-To: <20220607104946.18710-1-jslaby@suse.cz>
The code uses constants for sizes of dictionary substructures on many
places. Define 3 macros and use them in the code, so that loop bounds,
local variables and the dictionary always match. (And the loop bounds
are obvious now too.)
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
drivers/tty/vt/consolemap.c | 54 ++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 24 deletions(-)
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 5acafeea9afc..15aa10ff87ad 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -186,6 +186,10 @@ static unsigned short translations[][256] = {
static int inv_translate[MAX_NR_CONSOLES];
+#define UNI_DIRS 32U
+#define UNI_DIR_ROWS 32U
+#define UNI_ROW_GLYPHS 64U
+
/**
* struct uni_pagedict -- unicode directory
*
@@ -196,7 +200,7 @@ static int inv_translate[MAX_NR_CONSOLES];
* @inverse_trans_unicode: best-effort inverse mapping to unicode
*/
struct uni_pagedict {
- u16 **uni_pgdir[32];
+ u16 **uni_pgdir[UNI_DIRS];
unsigned long refcount;
unsigned long sum;
unsigned char *inverse_translations[4];
@@ -246,15 +250,15 @@ static void set_inverse_trans_unicode(struct vc_data *conp,
}
memset(q, 0, MAX_GLYPH * sizeof(u16));
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < UNI_DIRS; i++) {
p1 = p->uni_pgdir[i];
if (!p1)
continue;
- for (j = 0; j < 32; j++) {
+ for (j = 0; j < UNI_DIR_ROWS; j++) {
p2 = p1[j];
if (!p2)
continue;
- for (k = 0; k < 64; k++) {
+ for (k = 0; k < UNI_ROW_GLYPHS; k++) {
glyph = p2[k];
if (glyph >= 0 && glyph < MAX_GLYPH
&& q[glyph] < 32)
@@ -408,10 +412,10 @@ static void con_release_unimap(struct uni_pagedict *p)
int i, j;
if (p == dflt) dflt = NULL;
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < UNI_DIRS; i++) {
p1 = p->uni_pgdir[i];
if (p1 != NULL) {
- for (j = 0; j < 32; j++)
+ for (j = 0; j < UNI_DIR_ROWS; j++)
kfree(p1[j]);
kfree(p1);
}
@@ -451,25 +455,26 @@ static int con_unify_unimap(struct vc_data *conp, struct uni_pagedict *p)
q = *vc_cons[i].d->vc_uni_pagedir_loc;
if (!q || q == p || q->sum != p->sum)
continue;
- for (j = 0; j < 32; j++) {
+ for (j = 0; j < UNI_DIRS; j++) {
u16 **p1, **q1;
p1 = p->uni_pgdir[j]; q1 = q->uni_pgdir[j];
if (!p1 && !q1)
continue;
if (!p1 || !q1)
break;
- for (k = 0; k < 32; k++) {
+ for (k = 0; k < UNI_DIR_ROWS; k++) {
if (!p1[k] && !q1[k])
continue;
if (!p1[k] || !q1[k])
break;
- if (memcmp(p1[k], q1[k], 64*sizeof(u16)))
+ if (memcmp(p1[k], q1[k],
+ UNI_ROW_GLYPHS * sizeof(u16)))
break;
}
- if (k < 32)
+ if (k < UNI_DIR_ROWS)
break;
}
- if (j == 32) {
+ if (j == UNI_DIRS) {
q->refcount++;
*conp->vc_uni_pagedir_loc = q;
con_release_unimap(p);
@@ -488,18 +493,19 @@ con_insert_unipair(struct uni_pagedict *p, u_short unicode, u_short fontpos)
p1 = p->uni_pgdir[n = unicode >> 11];
if (!p1) {
- p1 = p->uni_pgdir[n] = kmalloc_array(32, sizeof(u16 *),
- GFP_KERNEL);
+ p1 = p->uni_pgdir[n] = kmalloc_array(UNI_DIR_ROWS,
+ sizeof(u16 *), GFP_KERNEL);
if (!p1) return -ENOMEM;
- for (i = 0; i < 32; i++)
+ for (i = 0; i < UNI_DIR_ROWS; i++)
p1[i] = NULL;
}
p2 = p1[n = (unicode >> 6) & 0x1f];
if (!p2) {
- p2 = p1[n] = kmalloc_array(64, sizeof(u16), GFP_KERNEL);
+ p2 = p1[n] = kmalloc_array(UNI_ROW_GLYPHS, sizeof(u16), GFP_KERNEL);
if (!p2) return -ENOMEM;
- memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */
+ /* No glyphs for the characters (yet) */
+ memset(p2, 0xff, UNI_ROW_GLYPHS * sizeof(u16));
}
p2[unicode & 0x3f] = fontpos;
@@ -589,13 +595,13 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
* entries from "p" (old) to "q" (new).
*/
l = 0; /* unicode value */
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < UNI_DIRS; i++) {
p1 = p->uni_pgdir[i];
if (p1)
- for (j = 0; j < 32; j++) {
+ for (j = 0; j < UNI_DIR_ROWS; j++) {
p2 = p1[j];
if (p2) {
- for (k = 0; k < 64; k++, l++)
+ for (k = 0; k < UNI_ROW_GLYPHS; k++, l++)
if (p2[k] != 0xffff) {
/*
* Found one, copy entry for unicode
@@ -613,12 +619,12 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
}
} else {
/* Account for row of 64 empty entries */
- l += 64;
+ l += UNI_ROW_GLYPHS;
}
}
else
/* Account for empty table */
- l += 32 * 64;
+ l += UNI_DIR_ROWS * UNI_ROW_GLYPHS;
}
/*
@@ -760,13 +766,13 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct uni
ect = 0;
if (*vc->vc_uni_pagedir_loc) {
p = *vc->vc_uni_pagedir_loc;
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < UNI_DIRS; i++) {
p1 = p->uni_pgdir[i];
if (p1)
- for (j = 0; j < 32; j++) {
+ for (j = 0; j < UNI_DIR_ROWS; j++) {
p2 = *(p1++);
if (p2)
- for (k = 0; k < 64; k++, p2++) {
+ for (k = 0; k < UNI_ROW_GLYPHS; k++, p2++) {
if (*p2 >= MAX_GLYPH)
continue;
if (ect < ct) {
--
2.36.1
next prev parent reply other threads:[~2022-06-07 10:51 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 ` Jiri Slaby [this message]
2022-06-07 13:21 ` [PATCH 03/36] tty/vt: consolemap: define UNI_* macros for constants 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 ` [PATCH 17/36] tty/vt: consolemap: introduce enum translation_map and use it Jiri Slaby
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-3-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