提交 92d2336e 编写于 作者: L Linus Torvalds 提交者: Zheng Zengkai

tty: clean up legacy leftovers from n_tty line discipline

stable inclusion
from stable-5.10.21
commit e761cd8a7853a69fcb01aea9e0cce1982ca2c264
bugzilla: 50609

--------------------------------

commit 64a69892 upstream.

Back when the line disciplines did their own direct user accesses, they
had to deal with the data copy possibly failing in the middle.

Now that the user copy is done by the tty_io.c code, that failure case
no longer exists.

Remove the left-over error handling code that cannot trigger.
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 8c9cdb1d
...@@ -1955,19 +1955,17 @@ static inline int input_available_p(struct tty_struct *tty, int poll) ...@@ -1955,19 +1955,17 @@ static inline int input_available_p(struct tty_struct *tty, int poll)
* read_tail published * read_tail published
*/ */
static int copy_from_read_buf(struct tty_struct *tty, static void copy_from_read_buf(struct tty_struct *tty,
unsigned char **kbp, unsigned char **kbp,
size_t *nr) size_t *nr)
{ {
struct n_tty_data *ldata = tty->disc_data; struct n_tty_data *ldata = tty->disc_data;
int retval;
size_t n; size_t n;
bool is_eof; bool is_eof;
size_t head = smp_load_acquire(&ldata->commit_head); size_t head = smp_load_acquire(&ldata->commit_head);
size_t tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1); size_t tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1);
retval = 0;
n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail); n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
n = min(*nr, n); n = min(*nr, n);
if (n) { if (n) {
...@@ -1984,7 +1982,6 @@ static int copy_from_read_buf(struct tty_struct *tty, ...@@ -1984,7 +1982,6 @@ static int copy_from_read_buf(struct tty_struct *tty,
*kbp += n; *kbp += n;
*nr -= n; *nr -= n;
} }
return retval;
} }
/** /**
...@@ -2010,7 +2007,7 @@ static int copy_from_read_buf(struct tty_struct *tty, ...@@ -2010,7 +2007,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
* read_tail published * read_tail published
*/ */
static int canon_copy_from_read_buf(struct tty_struct *tty, static void canon_copy_from_read_buf(struct tty_struct *tty,
unsigned char **kbp, unsigned char **kbp,
size_t *nr) size_t *nr)
{ {
...@@ -2022,7 +2019,7 @@ static int canon_copy_from_read_buf(struct tty_struct *tty, ...@@ -2022,7 +2019,7 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
/* N.B. avoid overrun if nr == 0 */ /* N.B. avoid overrun if nr == 0 */
if (!*nr) if (!*nr)
return 0; return;
n = min(*nr + 1, smp_load_acquire(&ldata->canon_head) - ldata->read_tail); n = min(*nr + 1, smp_load_acquire(&ldata->canon_head) - ldata->read_tail);
...@@ -2069,7 +2066,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty, ...@@ -2069,7 +2066,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
ldata->push = 0; ldata->push = 0;
tty_audit_push(); tty_audit_push();
} }
return 0;
} }
/** /**
...@@ -2219,24 +2215,17 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2219,24 +2215,17 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
} }
if (ldata->icanon && !L_EXTPROC(tty)) { if (ldata->icanon && !L_EXTPROC(tty)) {
retval = canon_copy_from_read_buf(tty, &kb, &nr); canon_copy_from_read_buf(tty, &kb, &nr);
if (retval)
break;
} else { } else {
int uncopied;
/* Deal with packet mode. */ /* Deal with packet mode. */
if (packet && kb == kbuf) { if (packet && kb == kbuf) {
*kb++ = TIOCPKT_DATA; *kb++ = TIOCPKT_DATA;
nr--; nr--;
} }
uncopied = copy_from_read_buf(tty, &kb, &nr); /* See comment above copy_from_read_buf() why twice */
uncopied += copy_from_read_buf(tty, &kb, &nr); copy_from_read_buf(tty, &kb, &nr);
if (uncopied) { copy_from_read_buf(tty, &kb, &nr);
retval = -EFAULT;
break;
}
} }
n_tty_check_unthrottle(tty); n_tty_check_unthrottle(tty);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册