tty: vt: simplify some unicode conditions
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Thu, 12 Jan 2023 08:01:33 +0000 (09:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jan 2023 14:06:42 +0000 (15:06 +0100)
After previous patches, we can simply test vc->vc_uni_lines, so do so in
many unicode functions. This makes the code more compact. And even use
  if (!)
    return;
in vc_uniscr_scroll(), so that the whole code is indented on the left.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230112080136.4929-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/vt.c

index f81f77464f8563cc04570f1bdcb6ceae6f5b0762..40d71cfdec326ff3dab6026a06089ae89ac01dc1 100644 (file)
@@ -357,18 +357,14 @@ static void vc_uniscr_set(struct vc_data *vc, u32 **new_uni_lines)
 
 static void vc_uniscr_putc(struct vc_data *vc, u32 uc)
 {
-       u32 **uni_lines = vc->vc_uni_lines;
-
-       if (uni_lines)
-               uni_lines[vc->state.y][vc->state.x] = uc;
+       if (vc->vc_uni_lines)
+               vc->vc_uni_lines[vc->state.y][vc->state.x] = uc;
 }
 
 static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
 {
-       u32 **uni_lines = vc->vc_uni_lines;
-
-       if (uni_lines) {
-               u32 *ln = uni_lines[vc->state.y];
+       if (vc->vc_uni_lines) {
+               u32 *ln = vc->vc_uni_lines[vc->state.y];
                unsigned int x = vc->state.x, cols = vc->vc_cols;
 
                memmove(&ln[x + nr], &ln[x], (cols - x - nr) * sizeof(*ln));
@@ -378,10 +374,8 @@ static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
 
 static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
 {
-       u32 **uni_lines = vc->vc_uni_lines;
-
-       if (uni_lines) {
-               u32 *ln = uni_lines[vc->state.y];
+       if (vc->vc_uni_lines) {
+               u32 *ln = vc->vc_uni_lines[vc->state.y];
                unsigned int x = vc->state.x, cols = vc->vc_cols;
 
                memcpy(&ln[x], &ln[x + nr], (cols - x - nr) * sizeof(*ln));
@@ -392,59 +386,52 @@ static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
 static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x,
                                 unsigned int nr)
 {
-       u32 **uni_lines = vc->vc_uni_lines;
-
-       if (uni_lines) {
-               u32 *ln = uni_lines[vc->state.y];
-
-               memset32(&ln[x], ' ', nr);
-       }
+       if (vc->vc_uni_lines)
+               memset32(&vc->vc_uni_lines[vc->state.y][x], ' ', nr);
 }
 
 static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
                                  unsigned int nr)
 {
-       u32 **uni_lines = vc->vc_uni_lines;
-
-       if (uni_lines) {
-               unsigned int cols = vc->vc_cols;
-
+       if (vc->vc_uni_lines)
                while (nr--)
-                       memset32(uni_lines[y++], ' ', cols);
-       }
+                       memset32(vc->vc_uni_lines[y++], ' ', vc->vc_cols);
 }
 
 static void vc_uniscr_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                             enum con_scroll dir, unsigned int nr)
 {
        u32 **uni_lines = vc->vc_uni_lines;
+       unsigned int i, j, k, sz, d, clear;
 
-       if (uni_lines) {
-               unsigned int i, j, k, sz, d, clear;
+       if (!uni_lines)
+               return;
 
-               sz = b - t;
-               clear = b - nr;
-               d = nr;
-               if (dir == SM_DOWN) {
-                       clear = t;
-                       d = sz - nr;
-               }
-               for (i = 0; i < gcd(d, sz); i++) {
-                       u32 *tmp = uni_lines[t + i];
-                       j = i;
-                       while (1) {
-                               k = j + d;
-                               if (k >= sz)
-                                       k -= sz;
-                               if (k == i)
-                                       break;
-                               uni_lines[t + j] = uni_lines[t + k];
-                               j = k;
-                       }
-                       uni_lines[t + j] = tmp;
+       sz = b - t;
+       clear = b - nr;
+       d = nr;
+
+       if (dir == SM_DOWN) {
+               clear = t;
+               d = sz - nr;
+       }
+
+       for (i = 0; i < gcd(d, sz); i++) {
+               u32 *tmp = uni_lines[t + i];
+               j = i;
+               while (1) {
+                       k = j + d;
+                       if (k >= sz)
+                               k -= sz;
+                       if (k == i)
+                               break;
+                       uni_lines[t + j] = uni_lines[t + k];
+                       j = k;
                }
-               vc_uniscr_clear_lines(vc, clear, nr);
+               uni_lines[t + j] = tmp;
        }
+
+       vc_uniscr_clear_lines(vc, clear, nr);
 }
 
 static void vc_uniscr_copy_area(u32 **dst_lines,