Merge 5.6-rc5 into tty-next
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Mar 2020 09:02:49 +0000 (10:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Mar 2020 09:02:49 +0000 (10:02 +0100)
We need the vt fixes in here and it resolves a merge issue with
drivers/tty/vt/selection.c

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1  2 
drivers/tty/serial/8250/8250_exar.c
drivers/tty/vt/selection.c
drivers/tty/vt/vt.c

Simple merge
index b9c517463efa1fefbb822268bfc38b1a2f532e16,d7d2e4b844bcd7fc316709bde2bed61e6613dd4c..1a069979866cbb7e749f35d1cebf3a1817d60614
@@@ -216,53 -211,57 +216,52 @@@ static int __set_selection_kernel(struc
                return 0;
        }
  
 -      if (ps > pe)    /* make sel_start <= sel_end */
 +      if (ps > pe)    /* make vc_sel.start <= vc_sel.end */
                swap(ps, pe);
  
 -      if (sel_cons != vc_cons[fg_console].d) {
 +      mutex_lock(&vc_sel.lock);
 +      if (vc_sel.cons != vc_cons[fg_console].d) {
                clear_selection();
 -              sel_cons = vc_cons[fg_console].d;
 +              vc_sel.cons = vc_cons[fg_console].d;
        }
 -      mode = vt_do_kdgkbmode(fg_console);
 -      if (mode == K_UNICODE)
 -              use_unicode = 1;
 -      else
 -              use_unicode = 0;
 -
 -      switch (v->sel_mode)
 -      {
 -              case TIOCL_SELCHAR:     /* character-by-character selection */
 +      unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 +
 +      switch (v->sel_mode) {
 +      case TIOCL_SELCHAR:     /* character-by-character selection */
 +              new_sel_start = ps;
 +              new_sel_end = pe;
 +              break;
 +      case TIOCL_SELWORD:     /* word-by-word selection */
 +              spc = isspace(sel_pos(ps, unicode));
 +              for (new_sel_start = ps; ; ps -= 2) {
 +                      if ((spc && !isspace(sel_pos(ps, unicode))) ||
 +                          (!spc && !inword(sel_pos(ps, unicode))))
 +                              break;
                        new_sel_start = ps;
 +                      if (!(ps % vc->vc_size_row))
 +                              break;
 +              }
 +
 +              spc = isspace(sel_pos(pe, unicode));
 +              for (new_sel_end = pe; ; pe += 2) {
 +                      if ((spc && !isspace(sel_pos(pe, unicode))) ||
 +                          (!spc && !inword(sel_pos(pe, unicode))))
 +                              break;
                        new_sel_end = pe;
 -                      break;
 -              case TIOCL_SELWORD:     /* word-by-word selection */
 -                      spc = isspace(sel_pos(ps));
 -                      for (new_sel_start = ps; ; ps -= 2)
 -                      {
 -                              if ((spc && !isspace(sel_pos(ps))) ||
 -                                  (!spc && !inword(sel_pos(ps))))
 -                                      break;
 -                              new_sel_start = ps;
 -                              if (!(ps % vc->vc_size_row))
 -                                      break;
 -                      }
 -                      spc = isspace(sel_pos(pe));
 -                      for (new_sel_end = pe; ; pe += 2)
 -                      {
 -                              if ((spc && !isspace(sel_pos(pe))) ||
 -                                  (!spc && !inword(sel_pos(pe))))
 -                                      break;
 -                              new_sel_end = pe;
 -                              if (!((pe + 2) % vc->vc_size_row))
 -                                      break;
 -                      }
 -                      break;
 -              case TIOCL_SELLINE:     /* line-by-line selection */
 -                      new_sel_start = ps - ps % vc->vc_size_row;
 -                      new_sel_end = pe + vc->vc_size_row
 -                                  - pe % vc->vc_size_row - 2;
 -                      break;
 -              case TIOCL_SELPOINTER:
 -                      highlight_pointer(pe);
 -                      return 0;
 -              default:
 -                      return -EINVAL;
 +                      if (!((pe + 2) % vc->vc_size_row))
 +                              break;
 +              }
 +              break;
 +      case TIOCL_SELLINE:     /* line-by-line selection */
 +              new_sel_start = ps - ps % vc->vc_size_row;
 +              new_sel_end = pe + vc->vc_size_row
 +                          - pe % vc->vc_size_row - 2;
 +              break;
 +      case TIOCL_SELPOINTER:
 +              highlight_pointer(pe);
-               goto unlock;
++              return 0;
 +      default:
-               ret = -EINVAL;
-               goto unlock;
++              return -EINVAL;
        }
  
        /* remove the pointer */
        /* select to end of line if on trailing space */
        if (new_sel_end > new_sel_start &&
                !atedge(new_sel_end, vc->vc_size_row) &&
 -              isspace(sel_pos(new_sel_end))) {
 +              isspace(sel_pos(new_sel_end, unicode))) {
                for (pe = new_sel_end + 2; ; pe += 2)
 -                      if (!isspace(sel_pos(pe)) ||
 +                      if (!isspace(sel_pos(pe, unicode)) ||
                            atedge(pe, vc->vc_size_row))
                                break;
 -              if (isspace(sel_pos(pe)))
 +              if (isspace(sel_pos(pe, unicode)))
                        new_sel_end = pe;
        }
 -      if (sel_start == -1)    /* no current selection */
 +      if (vc_sel.start == -1) /* no current selection */
                highlight(new_sel_start, new_sel_end);
 -      else if (new_sel_start == sel_start)
 +      else if (new_sel_start == vc_sel.start)
        {
 -              if (new_sel_end == sel_end)     /* no action required */
 +              if (new_sel_end == vc_sel.end)  /* no action required */
-                       goto unlock;
+                       return 0;
 -              else if (new_sel_end > sel_end) /* extend to right */
 -                      highlight(sel_end + 2, new_sel_end);
 +              else if (new_sel_end > vc_sel.end)      /* extend to right */
 +                      highlight(vc_sel.end + 2, new_sel_end);
                else                            /* contract from right */
 -                      highlight(new_sel_end + 2, sel_end);
 +                      highlight(new_sel_end + 2, vc_sel.end);
        }
 -      else if (new_sel_end == sel_end)
 +      else if (new_sel_end == vc_sel.end)
        {
 -              if (new_sel_start < sel_start)  /* extend to left */
 -                      highlight(new_sel_start, sel_start - 2);
 +              if (new_sel_start < vc_sel.start) /* extend to left */
 +                      highlight(new_sel_start, vc_sel.start - 2);
                else                            /* contract from left */
 -                      highlight(sel_start, new_sel_start - 2);
 +                      highlight(vc_sel.start, new_sel_start - 2);
        }
        else    /* some other case; start selection from scratch */
        {
        if (!bp) {
                printk(KERN_WARNING "selection: kmalloc() failed\n");
                clear_selection();
-               ret = -ENOMEM;
-               goto unlock;
+               return -ENOMEM;
        }
 -      kfree(sel_buffer);
 -      sel_buffer = bp;
 +      kfree(vc_sel.buffer);
 +      vc_sel.buffer = bp;
  
        obp = bp;
 -      for (i = sel_start; i <= sel_end; i += 2) {
 -              c = sel_pos(i);
 -              if (use_unicode)
 +      for (i = vc_sel.start; i <= vc_sel.end; i += 2) {
 +              c = sel_pos(i, unicode);
 +              if (unicode)
                        bp += store_utf8(c, bp);
                else
                        *bp++ = c;
                        obp = bp;
                }
        }
 -      sel_buffer_lth = bp - sel_buffer;
 +      vc_sel.buf_len = bp - vc_sel.buffer;
- unlock:
+       return ret;
+ }
+ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
+ {
+       int ret;
 -      mutex_lock(&sel_lock);
++      mutex_lock(&vc_sel.lock);
+       console_lock();
+       ret = __set_selection_kernel(v, tty);
+       console_unlock();
 -      mutex_unlock(&sel_lock);
 +      mutex_unlock(&vc_sel.lock);
        return ret;
  }
  EXPORT_SYMBOL_GPL(set_selection_kernel);
Simple merge