Commit 12e84c71 authored by Okash Khawaja's avatar Okash Khawaja Committed by Greg Kroah-Hartman

tty: export tty_open_by_driver

This exports tty_open_by_driver so that it can be called from other
places inside the kernel. The checks for null file pointer are based on
Alan Cox's patch here:
http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1215095.html.
Description below is quoted from it:

"[RFC] tty_port: allow a port to be opened with a tty that has no file handle

    Let us create tty objects entirely in kernel space. Untested proposal to
    show why all the ideas around rewriting half the uart stack are not needed.

    With this a kernel created non file backed tty object could be used to handle
    data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in
    particular has to work back to the fs/tty layer.

    The tty_port code is however otherwise clean of file handles as far as I can
    tell as is the low level tty port write path used by the ldisc, the
    configuration low level interfaces and most of the ldiscs.

    Currently you don't have any exposure to see tty hangups because those are
    built around the file layer. However a) it's a fixed port so you probably
    don't care about that b) if you do we can add a callback and c) you almost
    certainly don't want the userspace tear down/rebuild behaviour anyway.

    This should however be sufficient if we wanted for example to enumerate all
    the bluetooth bound fixed ports via ACPI and make them directly available.

    It doesn't deal with the case of a user opening a port that's also kernel
    opened and that would need some locking out (so it returned EBUSY if bound
    to a kernel device of some kind). That needs resolving along with how you
    "up" or "down" your new bluetooth device, or enumerate it while providing
    the existing tty API to avoid regressions (and to debug)."

The exported funtion is used later in this patch set to gain access to tty_struct.

[changed export symbol level - gkh]
Signed-off-by: default avatarOkash Khawaja <okash.khawaja@gmail.com>
Reviewed-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent caaba677
...@@ -1083,6 +1083,9 @@ static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, ...@@ -1083,6 +1083,9 @@ static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
struct tty_struct *tty; struct tty_struct *tty;
if (driver->ops->lookup) if (driver->ops->lookup)
if (!file)
tty = ERR_PTR(-EIO);
else
tty = driver->ops->lookup(driver, file, idx); tty = driver->ops->lookup(driver, file, idx);
else else
tty = driver->ttys[idx]; tty = driver->ttys[idx];
...@@ -1715,7 +1718,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, ...@@ -1715,7 +1718,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
struct tty_driver *console_driver = console_device(index); struct tty_driver *console_driver = console_device(index);
if (console_driver) { if (console_driver) {
driver = tty_driver_kref_get(console_driver); driver = tty_driver_kref_get(console_driver);
if (driver) { if (driver && filp) {
/* Don't let /dev/console block */ /* Don't let /dev/console block */
filp->f_flags |= O_NONBLOCK; filp->f_flags |= O_NONBLOCK;
break; break;
...@@ -1748,7 +1751,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, ...@@ -1748,7 +1751,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
* - concurrent tty driver removal w/ lookup * - concurrent tty driver removal w/ lookup
* - concurrent tty removal from driver table * - concurrent tty removal from driver table
*/ */
static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode, struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
struct file *filp) struct file *filp)
{ {
struct tty_struct *tty; struct tty_struct *tty;
...@@ -1793,6 +1796,7 @@ static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode, ...@@ -1793,6 +1796,7 @@ static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
tty_driver_kref_put(driver); tty_driver_kref_put(driver);
return tty; return tty;
} }
EXPORT_SYMBOL_GPL(tty_open_by_driver);
/** /**
* tty_open - open a tty device * tty_open - open a tty device
......
...@@ -400,6 +400,8 @@ extern struct tty_struct *get_current_tty(void); ...@@ -400,6 +400,8 @@ extern struct tty_struct *get_current_tty(void);
/* tty_io.c */ /* tty_io.c */
extern int __init tty_init(void); extern int __init tty_init(void);
extern const char *tty_name(const struct tty_struct *tty); extern const char *tty_name(const struct tty_struct *tty);
extern struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
struct file *filp);
#else #else
static inline void tty_kref_put(struct tty_struct *tty) static inline void tty_kref_put(struct tty_struct *tty)
{ } { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment