lkml.org 
[lkml]   [2019]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 1/2] tty: add retry capability to tty_init_dev()
Date
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
\
 
 \ /
  Last update: 2019-11-21 16:23    [W:0.088 / U:0.976 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site