aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2015-11-27 14:11:02 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-12-13 22:59:48 -0500
commit679e7c2999f963e542c6f4c3d3c9a0688b5d3587 (patch)
tree2fa3c704ac9a1d7cd8198b4cf6cb6968961b10fc /drivers/tty
parentafd7f88f157796e586fc99d62da13a54024e0731 (diff)
n_tty: Uninline tty_copy_to_user()
Merge the multiple tty_copy_to_user() calls into a single copy sequence within tty_copy_to_user(). Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/n_tty.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index c37c15d2f782..b2b01d5439b7 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -162,12 +162,23 @@ static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
162 return put_user(x, ptr); 162 return put_user(x, ptr);
163} 163}
164 164
165static inline int tty_copy_to_user(struct tty_struct *tty, 165static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
166 void __user *to, 166 size_t tail, size_t n)
167 const void *from,
168 unsigned long n)
169{ 167{
170 struct n_tty_data *ldata = tty->disc_data; 168 struct n_tty_data *ldata = tty->disc_data;
169 size_t size = N_TTY_BUF_SIZE - tail;
170 const void *from = read_buf_addr(ldata, tail);
171 int uncopied;
172
173 if (n > size) {
174 tty_audit_add_data(tty, from, size, ldata->icanon);
175 uncopied = copy_to_user(to, from, size);
176 if (uncopied)
177 return uncopied;
178 to += size;
179 n -= size;
180 from = ldata->read_buf;
181 }
171 182
172 tty_audit_add_data(tty, from, n, ldata->icanon); 183 tty_audit_add_data(tty, from, n, ldata->icanon);
173 return copy_to_user(to, from, n); 184 return copy_to_user(to, from, n);
@@ -2074,7 +2085,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
2074 } else if (eol != size) 2085 } else if (eol != size)
2075 found = 1; 2086 found = 1;
2076 2087
2077 size = N_TTY_BUF_SIZE - tail;
2078 n = eol - tail; 2088 n = eol - tail;
2079 if (n > N_TTY_BUF_SIZE) 2089 if (n > N_TTY_BUF_SIZE)
2080 n += N_TTY_BUF_SIZE; 2090 n += N_TTY_BUF_SIZE;
@@ -2086,17 +2096,10 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
2086 eof_push = !n && ldata->read_tail != ldata->line_start; 2096 eof_push = !n && ldata->read_tail != ldata->line_start;
2087 } 2097 }
2088 2098
2089 n_tty_trace("%s: eol:%zu found:%d n:%zu c:%zu size:%zu more:%zu\n", 2099 n_tty_trace("%s: eol:%zu found:%d n:%zu c:%zu tail:%zu more:%zu\n",
2090 __func__, eol, found, n, c, size, more); 2100 __func__, eol, found, n, c, tail, more);
2091
2092 if (n > size) {
2093 ret = tty_copy_to_user(tty, *b, read_buf_addr(ldata, tail), size);
2094 if (ret)
2095 return -EFAULT;
2096 ret = tty_copy_to_user(tty, *b + size, ldata->read_buf, n - size);
2097 } else
2098 ret = tty_copy_to_user(tty, *b, read_buf_addr(ldata, tail), n);
2099 2101
2102 ret = tty_copy_to_user(tty, *b, tail, n);
2100 if (ret) 2103 if (ret)
2101 return -EFAULT; 2104 return -EFAULT;
2102 *b += n; 2105 *b += n;