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
10831083 struct tty_struct *tty;
10841084
10851085 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);
10871090 else
10881091 tty = driver->ttys[idx];
10891092
@@ -1715,7 +1718,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, · 625 unmodified lines
17151718 struct tty_driver *console_driver = console_device(index);
17161719 if (console_driver) {
17171720 driver = tty_driver_kref_get(console_driver);
1718− if (driver) {
1721+ if (driver && filp) {
17191722 /* Don't let /dev/console block */
17201723 filp->f_flags |= O_NONBLOCK;
17211724 break;
@@ -1748,7 +1751,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, · 26 unmodified lines
17481751 * - concurrent tty driver removal w/ lookup
17491752 * - concurrent tty removal from driver table
17501753 */
1751−static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
1754+struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
17521755 struct file *filp)
17531756 {
17541757 struct tty_struct *tty;
@@ -1793,6 +1796,7 @@ out: · 38 unmodified lines
17931796 tty_driver_kref_put(driver);
17941797 return tty;
17951798 }
1799+EXPORT_SYMBOL_GPL(tty_open_by_driver);
17961800
17971801 /**
17981802 * 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
400400 /* tty_io.c */
401401 extern int __init tty_init(void);
402402 extern const char *tty_name(const struct tty_struct *tty);
403+extern struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode,
404+ struct file *filp);
403405 #else
404406 static inline void tty_kref_put(struct tty_struct *tty)
405407 { }