linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>
Cc: linux-kernel@vger.kernel.org,
	Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Subject: [PATCH v2 1/2] tty: add retry capability to tty_init_dev()
Date: Thu, 21 Nov 2019 15:22:38 +0000	[thread overview]
Message-ID: <20191121152239.28405-1-sudipm.mukherjee@gmail.com> (raw)

Add a new function tty_init_dev_retry() which will have the capability
to return if 'tty->port' is not yet set and if we want to retry. There
is no change in behaviour if we do not want to retry and call
tty_init_dev().

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---

v1 was a combined patch of this and the next 2/2 patch. Made them
separately now.

 drivers/tty/tty_io.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index e3076ea01222..95d7abeca254 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1291,9 +1291,10 @@ static int tty_reopen(struct tty_struct *tty)
 }
 
 /**
- *	tty_init_dev		-	initialise a tty device
+ *	tty_init_dev_retry	-	initialise a tty device
  *	@driver: tty driver we are opening a device on
  *	@idx: device index
+ *	@retry: retry count if driver has not set tty->port yet
  *	@ret_tty: returned tty structure
  *
  *	Prepare a tty device. This may not be a "new" clean device but
@@ -1314,7 +1315,8 @@ static int tty_reopen(struct tty_struct *tty)
  * relaxed for the (most common) case of reopening a tty.
  */
 
-struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
+static struct tty_struct *tty_init_dev_retry(struct tty_driver *driver,
+					     int idx, int retry)
 {
 	struct tty_struct *tty;
 	int retval;
@@ -1343,6 +1345,10 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
 
 	if (!tty->port)
 		tty->port = driver->ports[idx];
+	if (!tty->port && retry) {
+		retval = -EAGAIN;
+		goto err_release_driver;
+	}
 
 	WARN_RATELIMIT(!tty->port,
 			"%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
@@ -1365,6 +1371,8 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
 	/* Return the tty locked so that it cannot vanish under the caller */
 	return tty;
 
+err_release_driver:
+	tty_driver_remove_tty(driver, tty);
 err_free_tty:
 	tty_unlock(tty);
 	free_tty_struct(tty);
@@ -1384,6 +1392,19 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
 }
 
 /**
+ *	tty_init_dev		-	initialise a tty device
+ *	@driver: tty driver we are opening a device on
+ *	@idx: device index
+ *	@ret_tty: returned tty structure
+ *
+ *	Calls tty_init_dev_retry() with retry count of 0.
+ */
+struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
+{
+	return tty_init_dev_retry(driver, idx, 0);
+}
+
+/**
  * tty_save_termios() - save tty termios data in driver table
  * @tty: tty whose termios data to save
  *
-- 
2.11.0


             reply	other threads:[~2019-11-21 15:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21 15:22 Sudip Mukherjee [this message]
2019-11-21 15:22 ` [PATCH v2 2/2] tty: use tty_init_dev_retry() to workaround a race condition Sudip Mukherjee
2019-11-21 16:41   ` Greg Kroah-Hartman
2019-11-21 21:01     ` Sudip Mukherjee
2019-11-22  9:05       ` Jiri Slaby
2019-11-22  9:11         ` Jiri Slaby
2019-11-24  0:02           ` Sudip Mukherjee
2019-11-25 10:42             ` Jiri Slaby
2019-12-10 11:41         ` Sudip Mukherjee
2019-12-12 11:15           ` Greg Kroah-Hartman
2019-12-17 11:47             ` Sudip Mukherjee
2019-12-17 12:05               ` 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=20191121152239.28405-1-sudipm.mukherjee@gmail.com \
    --to=sudipm.mukherjee@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    /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).