summaryrefslogtreecommitdiff
path: root/drivers/tty/vt/vc_screen.c
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2020-08-18 11:57:05 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-08-18 14:45:22 +0300
commitb1c32fcfadf5593ab7a63261cc8a5747c36e627e (patch)
tree2b1b8c9a33b1cb3c8307ae4aedf2eaf2c6348de6 /drivers/tty/vt/vc_screen.c
parent6a6b76cc44c98a39d3e718aa2056e2e12b609615 (diff)
downloadlinux-b1c32fcfadf5593ab7a63261cc8a5747c36e627e.tar.xz
vc_screen: extract vcs_read_buf_header
The attribute header handling is terrible in vcs_read_buf. Separate it to a new function and simply do memmove (of up to 4 bytes) to the start of the con_buf -- if user seeked. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20200818085706.12163-15-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt/vc_screen.c')
-rw-r--r--drivers/tty/vt/vc_screen.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index c178a1611223..9d68c6b36ddf 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -297,6 +297,22 @@ static void vcs_read_buf_noattr(const struct vc_data *vc, char *con_buf,
}
}
+static unsigned int vcs_read_buf_header(const struct vc_data *vc, char *con_buf,
+ unsigned int pos, unsigned int count)
+{
+ count = min(HEADER_SIZE - pos, count);
+
+ /* clamp header values if they don't fit */
+ con_buf[0] = min(vc->vc_rows, 0xFFu);
+ con_buf[1] = min(vc->vc_cols, 0xFFu);
+ getconsxy(vc, con_buf + 2);
+
+ if (pos)
+ memmove(con_buf, con_buf + pos, count);
+
+ return count;
+}
+
static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf,
unsigned int pos, unsigned int count, bool viewed,
unsigned int *skip)
@@ -306,22 +322,11 @@ static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf,
unsigned int filled = count;
if (pos < HEADER_SIZE) {
- /* clamp header values if they don't fit */
- con_buf[0] = min(vc->vc_rows, 0xFFu);
- con_buf[1] = min(vc->vc_cols, 0xFFu);
- getconsxy(vc, con_buf + 2);
-
- *skip += pos;
- count += pos;
- if (count > CON_BUF_SIZE) {
- count = CON_BUF_SIZE;
- filled = count - pos;
- }
+ count -= vcs_read_buf_header(vc, con_buf, pos, count);
- /* Advance state pointers and move on. */
- count -= min(HEADER_SIZE, count);
pos = HEADER_SIZE;
con_buf += HEADER_SIZE;
+
/* If count >= 0, then pos is even... */
} else if (pos & 1) {
/*