linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: jirislaby@kernel.org, linux-serial@vger.kernel.org
Cc: gregkh@linuxfoundation.org, hch@lst.de, viro@zeniv.linux.org.uk,
	linux-kernel@vger.kernel.org, ohw.giles@gmail.com,
	r.karszniewicz@phytec.de,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4/6] tty: clean up legacy leftovers from n_tty line discipline
Date: Thu, 21 Jan 2021 10:00:18 +0100	[thread overview]
Message-ID: <20210121090020.3147058-4-gregkh@linuxfoundation.org> (raw)
In-Reply-To: <20210121090020.3147058-1-gregkh@linuxfoundation.org>

From: Linus Torvalds <torvalds@linux-foundation.org>

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>
---
 drivers/tty/n_tty.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 4a34a9f43b29..3a1a79462d16 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1955,19 +1955,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) {
@@ -1984,7 +1982,6 @@ static int copy_from_read_buf(struct tty_struct *tty,
 		*kbp += n;
 		*nr -= n;
 	}
-	return retval;
 }
 
 /**
@@ -2010,9 +2007,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;
@@ -2022,7 +2019,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);
 
@@ -2069,7 +2066,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
 			ldata->push = 0;
 		tty_audit_push();
 	}
-	return 0;
 }
 
 extern ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -2222,24 +2218,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);
-- 
2.30.0


  parent reply	other threads:[~2021-01-21  9:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21  9:00 [PATCH 1/6] tty: implement write_iter Greg Kroah-Hartman
2021-01-21  9:00 ` [PATCH 2/6] tty: convert tty_ldisc_ops 'read()' function to take a kernel pointer Greg Kroah-Hartman
2021-01-21 11:02   ` Jiri Slaby
2021-01-21 17:46     ` Linus Torvalds
2021-01-21 17:57       ` Greg Kroah-Hartman
2021-01-21  9:00 ` [PATCH 3/6] tty: implement read_iter Greg Kroah-Hartman
2021-01-21 10:44   ` Jiri Slaby
2021-01-21  9:00 ` Greg Kroah-Hartman [this message]
2021-01-21  9:00 ` [PATCH 5/6] tty: teach n_tty line discipline about the new "cookie continuations" Greg Kroah-Hartman
2021-01-21  9:00 ` [PATCH 6/6] tty: teach the n_tty ICANON case about the new "cookie continuations" too Greg Kroah-Hartman
2021-01-21  9:39 ` [PATCH 1/6] tty: implement write_iter Jiri Slaby
2021-01-21 17:44   ` Linus Torvalds
2021-01-21 17:57     ` Greg Kroah-Hartman
2021-01-21 18:42       ` Linus Torvalds
2021-01-21 19:43         ` Greg Kroah-Hartman
2021-01-21 21:09           ` Linus Torvalds
2021-01-22  7:07             ` Jiri Slaby
2021-01-22  7:33         ` Jiri Slaby
2021-01-22  7:43           ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121090020.3147058-4-gregkh@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=ohw.giles@gmail.com \
    --cc=r.karszniewicz@phytec.de \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).