Commit 1fc359fc authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Compute flip buffer ptrs

The char_buf_ptr and flag_buf_ptr values are trivially derived from
the .data field offset; compute values as needed.

Fixes a long-standing type-mismatch with the char and flag ptrs.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f0f947c1
...@@ -71,8 +71,6 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size) ...@@ -71,8 +71,6 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
p->next = NULL; p->next = NULL;
p->commit = 0; p->commit = 0;
p->read = 0; p->read = 0;
p->char_buf_ptr = (char *)(p->data);
p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
port->buf.memory_used += size; port->buf.memory_used += size;
return p; return p;
} }
...@@ -265,8 +263,8 @@ int tty_insert_flip_string_fixed_flag(struct tty_port *port, ...@@ -265,8 +263,8 @@ int tty_insert_flip_string_fixed_flag(struct tty_port *port,
if (unlikely(space == 0)) { if (unlikely(space == 0)) {
break; break;
} }
memcpy(tb->char_buf_ptr + tb->used, chars, space); memcpy(char_buf_ptr(tb, tb->used), chars, space);
memset(tb->flag_buf_ptr + tb->used, flag, space); memset(flag_buf_ptr(tb, tb->used), flag, space);
tb->used += space; tb->used += space;
copied += space; copied += space;
chars += space; chars += space;
...@@ -303,8 +301,8 @@ int tty_insert_flip_string_flags(struct tty_port *port, ...@@ -303,8 +301,8 @@ int tty_insert_flip_string_flags(struct tty_port *port,
if (unlikely(space == 0)) { if (unlikely(space == 0)) {
break; break;
} }
memcpy(tb->char_buf_ptr + tb->used, chars, space); memcpy(char_buf_ptr(tb, tb->used), chars, space);
memcpy(tb->flag_buf_ptr + tb->used, flags, space); memcpy(flag_buf_ptr(tb, tb->used), flags, space);
tb->used += space; tb->used += space;
copied += space; copied += space;
chars += space; chars += space;
...@@ -364,8 +362,8 @@ int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars, ...@@ -364,8 +362,8 @@ int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
int space = tty_buffer_request_room(port, size); int space = tty_buffer_request_room(port, size);
if (likely(space)) { if (likely(space)) {
struct tty_buffer *tb = port->buf.tail; struct tty_buffer *tb = port->buf.tail;
*chars = tb->char_buf_ptr + tb->used; *chars = char_buf_ptr(tb, tb->used);
memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); memset(flag_buf_ptr(tb, tb->used), TTY_NORMAL, space);
tb->used += space; tb->used += space;
} }
return space; return space;
...@@ -394,8 +392,8 @@ int tty_prepare_flip_string_flags(struct tty_port *port, ...@@ -394,8 +392,8 @@ int tty_prepare_flip_string_flags(struct tty_port *port,
int space = tty_buffer_request_room(port, size); int space = tty_buffer_request_room(port, size);
if (likely(space)) { if (likely(space)) {
struct tty_buffer *tb = port->buf.tail; struct tty_buffer *tb = port->buf.tail;
*chars = tb->char_buf_ptr + tb->used; *chars = char_buf_ptr(tb, tb->used);
*flags = tb->flag_buf_ptr + tb->used; *flags = flag_buf_ptr(tb, tb->used);
tb->used += space; tb->used += space;
} }
return space; return space;
...@@ -407,8 +405,8 @@ static int ...@@ -407,8 +405,8 @@ static int
receive_buf(struct tty_struct *tty, struct tty_buffer *head, int count) receive_buf(struct tty_struct *tty, struct tty_buffer *head, int count)
{ {
struct tty_ldisc *disc = tty->ldisc; struct tty_ldisc *disc = tty->ldisc;
char *p = head->char_buf_ptr + head->read; unsigned char *p = char_buf_ptr(head, head->read);
unsigned char *f = head->flag_buf_ptr + head->read; char *f = flag_buf_ptr(head, head->read);
if (disc->ops->receive_buf2) if (disc->ops->receive_buf2)
count = disc->ops->receive_buf2(tty, p, f, count); count = disc->ops->receive_buf2(tty, p, f, count);
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
struct tty_buffer { struct tty_buffer {
struct tty_buffer *next; struct tty_buffer *next;
char *char_buf_ptr;
unsigned char *flag_buf_ptr;
int used; int used;
int size; int size;
int commit; int commit;
...@@ -41,6 +39,16 @@ struct tty_buffer { ...@@ -41,6 +39,16 @@ struct tty_buffer {
unsigned long data[0]; unsigned long data[0];
}; };
static inline unsigned char *char_buf_ptr(struct tty_buffer *b, int ofs)
{
return ((unsigned char *)b->data) + ofs;
}
static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs)
{
return (char *)char_buf_ptr(b, ofs) + b->size;
}
/* /*
* We default to dicing tty buffer allocations to this many characters * We default to dicing tty buffer allocations to this many characters
* in order to avoid multiple page allocations. We know the size of * in order to avoid multiple page allocations. We know the size of
......
...@@ -18,8 +18,8 @@ static inline int tty_insert_flip_char(struct tty_port *port, ...@@ -18,8 +18,8 @@ static inline int tty_insert_flip_char(struct tty_port *port,
{ {
struct tty_buffer *tb = port->buf.tail; struct tty_buffer *tb = port->buf.tail;
if (tb && tb->used < tb->size) { if (tb && tb->used < tb->size) {
tb->flag_buf_ptr[tb->used] = flag; *flag_buf_ptr(tb, tb->used) = flag;
tb->char_buf_ptr[tb->used++] = ch; *char_buf_ptr(tb, tb->used++) = ch;
return 1; return 1;
} }
return tty_insert_flip_string_flags(port, &ch, &flag, 1); return tty_insert_flip_string_flags(port, &ch, &flag, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment