Skip to content

Commit

Permalink
tty: clean up legacy leftovers from n_tty line discipline
Browse files Browse the repository at this point in the history
commit 64a6989 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: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
torvalds authored and gregkh committed Mar 7, 2021
1 parent 434254d commit 7f68c3b
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions drivers/tty/n_tty.c
Expand Up @@ -1957,19 +1957,17 @@ static inline int input_available_p(struct tty_struct *tty, int poll)
* 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,
size_t *nr)

{
struct n_tty_data *ldata = tty->disc_data;
int retval;
size_t n;
bool is_eof;
size_t head = smp_load_acquire(&ldata->commit_head);
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(*nr, n);
if (n) {
Expand All @@ -1986,7 +1984,6 @@ static int copy_from_read_buf(struct tty_struct *tty,
*kbp += n;
*nr -= n;
}
return retval;
}

/**
Expand All @@ -2012,9 +2009,9 @@ static int copy_from_read_buf(struct tty_struct *tty,
* read_tail published
*/

static int canon_copy_from_read_buf(struct tty_struct *tty,
unsigned char **kbp,
size_t *nr)
static void canon_copy_from_read_buf(struct tty_struct *tty,
unsigned char **kbp,
size_t *nr)
{
struct n_tty_data *ldata = tty->disc_data;
size_t n, size, more, c;
Expand All @@ -2024,7 +2021,7 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,

/* N.B. avoid overrun if nr == 0 */
if (!*nr)
return 0;
return;

n = min(*nr + 1, smp_load_acquire(&ldata->canon_head) - ldata->read_tail);

Expand Down Expand Up @@ -2071,7 +2068,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
ldata->push = 0;
tty_audit_push();
}
return 0;
}

/**
Expand Down Expand Up @@ -2221,24 +2217,17 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
}

if (ldata->icanon && !L_EXTPROC(tty)) {
retval = canon_copy_from_read_buf(tty, &kb, &nr);
if (retval)
break;
canon_copy_from_read_buf(tty, &kb, &nr);
} else {
int uncopied;

/* Deal with packet mode. */
if (packet && kb == kbuf) {
*kb++ = TIOCPKT_DATA;
nr--;
}

uncopied = copy_from_read_buf(tty, &kb, &nr);
uncopied += copy_from_read_buf(tty, &kb, &nr);
if (uncopied) {
retval = -EFAULT;
break;
}
/* See comment above copy_from_read_buf() why twice */
copy_from_read_buf(tty, &kb, &nr);
copy_from_read_buf(tty, &kb, &nr);
}

n_tty_check_unthrottle(tty);
Expand Down

0 comments on commit 7f68c3b

Please sign in to comment.