vt: use tty_insert_flip_string in respond_string

Pass the length of a string to respond_string and use
tty_insert_flip_string instead of a loop with tty_insert_flip_char. This
simplifies the processing on the tty side.

The added strlens are optimized during constant folding and propagation
and the result are proper constants in assembly.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20200615074910.19267-8-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jiri Slaby 2020-06-15 09:48:40 +02:00 committed by Greg Kroah-Hartman
parent 7d4a3112f0
commit de53ce0427

View file

@ -1809,40 +1809,43 @@ static void csi_m(struct vc_data *vc)
update_attr(vc);
}
static void respond_string(const char *p, struct tty_port *port)
static void respond_string(const char *p, size_t len, struct tty_port *port)
{
while (*p) {
tty_insert_flip_char(port, *p, 0);
p++;
}
tty_insert_flip_string(port, p, len);
tty_schedule_flip(port);
}
static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
{
char buf[40];
int len;
sprintf(buf, "\033[%d;%dR", vc->state.y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->state.x + 1);
respond_string(buf, tty->port);
len = sprintf(buf, "\033[%d;%dR", vc->state.y +
(vc->vc_decom ? vc->vc_top + 1 : 1),
vc->state.x + 1);
respond_string(buf, len, tty->port);
}
static inline void status_report(struct tty_struct *tty)
{
respond_string("\033[0n", tty->port); /* Terminal ok */
static const char teminal_ok[] = "\033[0n";
respond_string(teminal_ok, strlen(teminal_ok), tty->port);
}
static inline void respond_ID(struct tty_struct *tty)
{
respond_string(VT102ID, tty->port);
respond_string(VT102ID, strlen(VT102ID), tty->port);
}
void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry)
{
char buf[8];
int len;
sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
(char)('!' + mry));
respond_string(buf, tty->port);
len = sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt),
(char)('!' + mrx), (char)('!' + mry));
respond_string(buf, len, tty->port);
}
/* invoked via ioctl(TIOCLINUX) and through set_selection_user */