History

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]

Okash Khawaja committed 9 years ago

Commit 12e84c71 parent caaba672 files · +9 −3Browse files

Unified · Split

2 files
  1. drivers/tty/tty_io.c +7 −3
  2. include/linux/tty.h +2 −0
drivers/tty/tty_io.c+7−3
@@ -1083,7 +1083,10 @@ static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, · 1082 unmodified lines
1083 struct tty_struct *tty;1083 struct tty_struct *tty;
1084 1084
1085 if (driver->ops->lookup)1085 if (driver->ops->lookup)
1086 tty = driver->ops->lookup(driver, file, idx);1086 if (!file)
1087 tty = ERR_PTR(-EIO);
1088 else
1089 tty = driver->ops->lookup(driver, file, idx);
1087 else1090 else
1088 tty = driver->ttys[idx];1091 tty = driver->ttys[idx];
1089 1092
@@ -1715,7 +1718,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, · 625 unmodified lines
1715 struct tty_driver *console_driver = console_device(index);1718 struct tty_driver *console_driver = console_device(index);
1716 if (console_driver) {1719 if (console_driver) {
1717 driver = tty_driver_kref_get(console_driver);1720 driver = tty_driver_kref_get(console_driver);
1718 if (driver) {1721 if (driver && filp) {
1719 /* Don't let /dev/console block */1722 /* Don't let /dev/console block */
1720 filp->f_flags |= O_NONBLOCK;1723 filp->f_flags |= O_NONBLOCK;
1721 break;1724 break;
@@ -1748,7 +1751,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, · 26 unmodified lines
1748 * - concurrent tty driver removal w/ lookup1751 * - concurrent tty driver removal w/ lookup
1749 * - concurrent tty removal from driver table1752 * - concurrent tty removal from driver table
1750 */1753 */
1751static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,1754struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
1752 struct file *filp)1755 struct file *filp)
1753{1756{
1754 struct tty_struct *tty;1757 struct tty_struct *tty;
@@ -1793,6 +1796,7 @@ out: · 38 unmodified lines
1793 tty_driver_kref_put(driver);1796 tty_driver_kref_put(driver);
1794 return tty;1797 return tty;
1795}1798}
1799EXPORT_SYMBOL_GPL(tty_open_by_driver);
1796 1800
1797/**1801/**
1798 * tty_open - open a tty device1802 * tty_open - open a tty device
include/linux/tty.h+2−0
@@ -400,6 +400,8 @@ extern struct tty_struct *get_current_tty(void); · 399 unmodified lines
400/* tty_io.c */400/* tty_io.c */
401extern int __init tty_init(void);401extern int __init tty_init(void);
402extern const char *tty_name(const struct tty_struct *tty);402extern const char *tty_name(const struct tty_struct *tty);
403extern struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
404 struct file *filp);
403#else405#else
404static inline void tty_kref_put(struct tty_struct *tty)406static inline void tty_kref_put(struct tty_struct *tty)
405{ }407{ }