Lines Matching full:tty

7  * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles
16 * dynamically allocated only when the tty is open.
19 * between the high-level tty routines (tty_io.c and tty_ioctl.c) and
20 * the low-level tty routines (serial.c, pty.c, console.c). This
31 * Added functionality to the OPOST tty handling. No delays, but all
76 #include <linux/tty.h>
112 #include "tty.h"
116 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) argument
118 # define tty_debug_hangup(tty, f, args...) do { } while (0) argument
124 struct ktermios tty_std_termios = { /* for the benefit of tty drivers */
138 * could do with some rationalisation such as pulling the tty proc function
142 LIST_HEAD(tty_drivers); /* linked list of tty drivers */
144 /* Mutex to protect creating and releasing a tty */
159 static void release_tty(struct tty_struct *tty, int idx);
162 * free_tty_struct - free a disused tty
163 * @tty: tty struct to free
165 * Free the write buffers, tty queue and tty memory itself.
167 * Locking: none. Must be called after tty is definitely unused
169 static void free_tty_struct(struct tty_struct *tty) in free_tty_struct() argument
171 tty_ldisc_deinit(tty); in free_tty_struct()
172 put_device(tty->dev); in free_tty_struct()
173 kvfree(tty->write_buf); in free_tty_struct()
174 kfree(tty); in free_tty_struct()
179 return ((struct tty_file_private *)file->private_data)->tty; in file_tty()
195 /* Associate a new file with the tty structure */
196 void tty_add_file(struct tty_struct *tty, struct file *file) in tty_add_file() argument
200 priv->tty = tty; in tty_add_file()
203 spin_lock(&tty->files_lock); in tty_add_file()
204 list_add(&priv->list, &tty->tty_files); in tty_add_file()
205 spin_unlock(&tty->files_lock); in tty_add_file()
223 /* Delete file from its tty */
227 struct tty_struct *tty = priv->tty; in tty_del_file() local
229 spin_lock(&tty->files_lock); in tty_del_file()
231 spin_unlock(&tty->files_lock); in tty_del_file()
236 * tty_name - return tty naming
237 * @tty: tty structure
239 * Convert a tty structure into a name. The name reflects the kernel naming
244 const char *tty_name(const struct tty_struct *tty) in tty_name() argument
246 if (!tty) /* Hmm. NULL pointer. That's fun. */ in tty_name()
247 return "NULL tty"; in tty_name()
248 return tty->name; in tty_name()
252 const char *tty_driver_name(const struct tty_struct *tty) in tty_driver_name() argument
254 if (!tty || !tty->driver) in tty_driver_name()
256 return tty->driver->name; in tty_driver_name()
259 static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, in tty_paranoia_check() argument
263 if (!tty) { in tty_paranoia_check()
264 pr_warn("(%d:%d): %s: NULL tty\n", in tty_paranoia_check()
273 static void check_tty_count(struct tty_struct *tty, const char *routine) in check_tty_count() argument
279 scoped_guard(spinlock, &tty->files_lock) in check_tty_count()
280 list_for_each(p, &tty->tty_files) in check_tty_count()
283 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in check_tty_count()
284 tty->driver->subtype == PTY_TYPE_SLAVE && in check_tty_count()
285 tty->link && tty->link->count) in check_tty_count()
287 if (tty_port_kopened(tty->port)) in check_tty_count()
289 if (tty->count != (count + kopen_count)) { in check_tty_count()
290 tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", in check_tty_count()
291 routine, tty->count, count, kopen_count); in check_tty_count()
297 * get_tty_driver - find device of a tty
299 * @index: returns the index of the tty
301 * This routine returns a tty driver structure, given a device number and also
371 * tty_find_polling_driver - find device of a polled tty
373 * @line: pointer to resulting tty line nr
375 * This routine returns a tty driver structure, given a name and the condition
376 * that the tty driver is capable of polled operation.
396 /* Search through the tty devices to look for a match */ in tty_find_polling_driver()
453 struct tty_struct *tty = file_tty(file); in tty_show_fdinfo() local
455 if (tty && tty->ops && tty->ops->show_fdinfo) in tty_show_fdinfo()
456 tty->ops->show_fdinfo(tty, m); in tty_show_fdinfo()
501 * @tty: terminal
503 * Internal and external helper for wakeups of tty. This function informs the
507 void tty_wakeup(struct tty_struct *tty) in tty_wakeup() argument
511 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { in tty_wakeup()
512 ld = tty_ldisc_ref(tty); in tty_wakeup()
515 ld->ops->write_wakeup(tty); in tty_wakeup()
519 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_wakeup()
525 * @tty: tty device
530 static struct file *tty_release_redirect(struct tty_struct *tty) in tty_release_redirect() argument
534 if (redirect && file_tty(redirect) == tty) { in tty_release_redirect()
545 * @tty: tty device
554 * hangup and signal delivery. The tty object itself remains intact.
568 static void __tty_hangup(struct tty_struct *tty, int exit_session) in __tty_hangup() argument
576 if (!tty) in __tty_hangup()
579 f = tty_release_redirect(tty); in __tty_hangup()
581 tty_lock(tty); in __tty_hangup()
583 if (test_bit(TTY_HUPPED, &tty->flags)) { in __tty_hangup()
584 tty_unlock(tty); in __tty_hangup()
594 set_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
596 /* inuse_filps is protected by the single tty lock, in __tty_hangup()
600 check_tty_count(tty, "tty_hangup"); in __tty_hangup()
602 spin_lock(&tty->files_lock); in __tty_hangup()
604 list_for_each_entry(priv, &tty->tty_files, list) { in __tty_hangup()
614 spin_unlock(&tty->files_lock); in __tty_hangup()
616 refs = tty_signal_session_leader(tty, exit_session); in __tty_hangup()
619 tty_kref_put(tty); in __tty_hangup()
621 tty_ldisc_hangup(tty, cons_filp != NULL); in __tty_hangup()
623 spin_lock_irq(&tty->ctrl.lock); in __tty_hangup()
624 clear_bit(TTY_THROTTLED, &tty->flags); in __tty_hangup()
625 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in __tty_hangup()
626 put_pid(tty->ctrl.session); in __tty_hangup()
627 put_pid(tty->ctrl.pgrp); in __tty_hangup()
628 tty->ctrl.session = NULL; in __tty_hangup()
629 tty->ctrl.pgrp = NULL; in __tty_hangup()
630 tty->ctrl.pktstatus = 0; in __tty_hangup()
631 spin_unlock_irq(&tty->ctrl.lock); in __tty_hangup()
636 * tty->count and state->count to go out of sync. in __tty_hangup()
640 if (tty->ops->close) in __tty_hangup()
642 tty->ops->close(tty, cons_filp); in __tty_hangup()
643 } else if (tty->ops->hangup) in __tty_hangup()
644 tty->ops->hangup(tty); in __tty_hangup()
650 set_bit(TTY_HUPPED, &tty->flags); in __tty_hangup()
651 clear_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
652 tty_unlock(tty); in __tty_hangup()
660 struct tty_struct *tty = in do_tty_hangup() local
663 __tty_hangup(tty, 0); in do_tty_hangup()
668 * @tty: tty to hangup
670 * A carrier loss (virtual or otherwise) has occurred on @tty. Schedule a
673 void tty_hangup(struct tty_struct *tty) in tty_hangup() argument
675 tty_debug_hangup(tty, "hangup\n"); in tty_hangup()
676 schedule_work(&tty->hangup_work); in tty_hangup()
682 * @tty: tty to hangup
688 void tty_vhangup(struct tty_struct *tty) in tty_vhangup() argument
690 tty_debug_hangup(tty, "vhangup\n"); in tty_vhangup()
691 __tty_hangup(tty, 0); in tty_vhangup()
699 * Perform a vhangup on the current controlling tty
703 struct tty_struct *tty; in tty_vhangup_self() local
705 tty = get_current_tty(); in tty_vhangup_self()
706 if (tty) { in tty_vhangup_self()
707 tty_vhangup(tty); in tty_vhangup_self()
708 tty_kref_put(tty); in tty_vhangup_self()
714 * @tty: tty to hangup
722 void tty_vhangup_session(struct tty_struct *tty) in tty_vhangup_session() argument
724 tty_debug_hangup(tty, "session hangup\n"); in tty_vhangup_session()
725 __tty_hangup(tty, 1); in tty_vhangup_session()
729 * tty_hung_up_p - was tty hung up
730 * @filp: file pointer of tty
732 * Return: true if the tty has been subject to a vhangup or a carrier loss
740 void __stop_tty(struct tty_struct *tty) in __stop_tty() argument
742 if (tty->flow.stopped) in __stop_tty()
744 tty->flow.stopped = true; in __stop_tty()
745 if (tty->ops->stop) in __stop_tty()
746 tty->ops->stop(tty); in __stop_tty()
751 * @tty: tty to stop
758 * under the tty %atomic_write_lock but not always.
763 void stop_tty(struct tty_struct *tty) in stop_tty() argument
765 guard(spinlock_irqsave)(&tty->flow.lock); in stop_tty()
766 __stop_tty(tty); in stop_tty()
770 void __start_tty(struct tty_struct *tty) in __start_tty() argument
772 if (!tty->flow.stopped || tty->flow.tco_stopped) in __start_tty()
774 tty->flow.stopped = false; in __start_tty()
775 if (tty->ops->start) in __start_tty()
776 tty->ops->start(tty); in __start_tty()
777 tty_wakeup(tty); in __start_tty()
782 * @tty: tty to start
784 * Start a tty that has been stopped if at all possible. If @tty was previously
791 void start_tty(struct tty_struct *tty) in start_tty() argument
793 guard(spinlock_irqsave)(&tty->flow.lock); in start_tty()
794 __start_tty(tty); in start_tty()
798 static void tty_update_time(struct tty_struct *tty, bool mtime) in tty_update_time() argument
803 guard(spinlock)(&tty->files_lock); in tty_update_time()
805 list_for_each_entry(priv, &tty->tty_files, list) { in tty_update_time()
812 * the time of the tty device, otherwise it could be construded as a in tty_update_time()
813 * security leak to let userspace know the exact timing of the tty. in tty_update_time()
835 static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, in iterate_tty_read() argument
847 size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); in iterate_tty_read()
883 /* We always clear tty buffer in case they contained passwords */ in iterate_tty_read()
890 * tty_read - read method for tty device files
905 struct tty_struct *tty = file_tty(file); in tty_read() local
909 if (tty_paranoia_check(tty, inode, "tty_read")) in tty_read()
911 if (!tty || tty_io_error(tty)) in tty_read()
917 ld = tty_ldisc_ref_wait(tty); in tty_read()
922 ret = iterate_tty_read(ld, tty, file, to); in tty_read()
926 tty_update_time(tty, false); in tty_read()
931 void tty_write_unlock(struct tty_struct *tty) in tty_write_unlock() argument
933 mutex_unlock(&tty->atomic_write_lock); in tty_write_unlock()
934 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_write_unlock()
937 int tty_write_lock(struct tty_struct *tty, bool ndelay) in tty_write_lock() argument
939 if (!mutex_trylock(&tty->atomic_write_lock)) { in tty_write_lock()
942 if (mutex_lock_interruptible(&tty->atomic_write_lock)) in tty_write_lock()
952 static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, in iterate_tty_write() argument
958 ret = tty_write_lock(tty, file->f_flags & O_NDELAY); in iterate_tty_write()
976 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) in iterate_tty_write()
982 if (tty->write_cnt < chunk) { in iterate_tty_write()
993 kvfree(tty->write_buf); in iterate_tty_write()
994 tty->write_cnt = chunk; in iterate_tty_write()
995 tty->write_buf = buf_chunk; in iterate_tty_write()
1003 if (copy_from_iter(tty->write_buf, size, from) != size) in iterate_tty_write()
1006 ret = ld->ops->write(tty, file, tty->write_buf, size); in iterate_tty_write()
1027 tty_update_time(tty, true); in iterate_tty_write()
1031 tty_write_unlock(tty); in iterate_tty_write()
1037 * tty_write_message - write a message to a certain tty, not just the console.
1038 * @tty: the destination tty_struct
1041 * This is used for messages that need to be redirected to a specific tty. We
1049 void tty_write_message(struct tty_struct *tty, char *msg) in tty_write_message() argument
1051 if (tty) { in tty_write_message()
1052 mutex_lock(&tty->atomic_write_lock); in tty_write_message()
1053 tty_lock(tty); in tty_write_message()
1054 if (tty->ops->write && tty->count > 0) in tty_write_message()
1055 tty->ops->write(tty, msg, strlen(msg)); in tty_write_message()
1056 tty_unlock(tty); in tty_write_message()
1057 tty_write_unlock(tty); in tty_write_message()
1064 struct tty_struct *tty = file_tty(file); in file_tty_write() local
1068 if (tty_paranoia_check(tty, file_inode(file), "tty_write")) in file_tty_write()
1070 if (!tty || !tty->ops->write || tty_io_error(tty)) in file_tty_write()
1073 if (tty->ops->write_room == NULL) in file_tty_write()
1074 tty_err(tty, "missing write_room method\n"); in file_tty_write()
1075 ld = tty_ldisc_ref_wait(tty); in file_tty_write()
1081 ret = iterate_tty_write(ld, tty, file, from); in file_tty_write()
1087 * tty_write - write method for tty device file
1091 * Write data to a tty device via the line discipline.
1095 * Writes to the tty driver are serialized by the atomic_write_lock
1115 * We know the redirected tty is just another tty, we can in redirected_tty_write()
1130 * @tty: the tty to send to
1133 * Send a high priority character to the tty even if stopped.
1137 int tty_send_xchar(struct tty_struct *tty, u8 ch) in tty_send_xchar() argument
1139 bool was_stopped = tty->flow.stopped; in tty_send_xchar()
1141 if (tty->ops->send_xchar) { in tty_send_xchar()
1142 down_read(&tty->termios_rwsem); in tty_send_xchar()
1143 tty->ops->send_xchar(tty, ch); in tty_send_xchar()
1144 up_read(&tty->termios_rwsem); in tty_send_xchar()
1148 if (tty_write_lock(tty, false) < 0) in tty_send_xchar()
1151 down_read(&tty->termios_rwsem); in tty_send_xchar()
1153 start_tty(tty); in tty_send_xchar()
1154 tty->ops->write(tty, &ch, 1); in tty_send_xchar()
1156 stop_tty(tty); in tty_send_xchar()
1157 up_read(&tty->termios_rwsem); in tty_send_xchar()
1158 tty_write_unlock(tty); in tty_send_xchar()
1164 * @driver: the tty driver in use
1177 /* ->name is initialized to "ttyp", but "tty" is expected */ in pty_line_name()
1179 driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name, in pty_line_name()
1184 * tty_line_name - generate name for a tty
1185 * @driver: the tty driver in use
1204 * tty_driver_lookup_tty() - find an existing tty, if any
1205 * @driver: the driver for the tty
1209 * Return: the tty, if found. If not found, return %NULL or ERR_PTR() if the
1212 * Locking: tty_mutex must be held. If the tty is found, bump the tty kref.
1217 struct tty_struct *tty; in tty_driver_lookup_tty() local
1221 tty = ERR_PTR(-EIO); in tty_driver_lookup_tty()
1223 tty = driver->ops->lookup(driver, file, idx); in tty_driver_lookup_tty()
1227 tty = driver->ttys[idx]; in tty_driver_lookup_tty()
1229 if (!IS_ERR(tty)) in tty_driver_lookup_tty()
1230 tty_kref_get(tty); in tty_driver_lookup_tty()
1231 return tty; in tty_driver_lookup_tty()
1236 * @tty: the tty to set up
1238 * Initialise the termios structure for this tty. This runs under the
1241 void tty_init_termios(struct tty_struct *tty) in tty_init_termios() argument
1244 int idx = tty->index; in tty_init_termios()
1246 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_init_termios()
1247 tty->termios = tty->driver->init_termios; in tty_init_termios()
1250 tp = tty->driver->termios[idx]; in tty_init_termios()
1252 tty->termios = *tp; in tty_init_termios()
1253 tty->termios.c_line = tty->driver->init_termios.c_line; in tty_init_termios()
1255 tty->termios = tty->driver->init_termios; in tty_init_termios()
1258 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); in tty_init_termios()
1259 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); in tty_init_termios()
1264 * tty_standard_install - usual tty->ops->install
1265 * @driver: the driver for the tty
1266 * @tty: the tty
1268 * If the @driver overrides @tty->ops->install, it still can call this function
1271 int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty) in tty_standard_install() argument
1273 tty_init_termios(tty); in tty_standard_install()
1275 tty->count++; in tty_standard_install()
1276 driver->ttys[tty->index] = tty; in tty_standard_install()
1282 * tty_driver_install_tty() - install a tty entry in the driver
1283 * @driver: the driver for the tty
1284 * @tty: the tty
1286 * Install a tty object into the driver tables. The @tty->index field will be
1293 struct tty_struct *tty) in tty_driver_install_tty() argument
1295 return driver->ops->install ? driver->ops->install(driver, tty) : in tty_driver_install_tty()
1296 tty_standard_install(driver, tty); in tty_driver_install_tty()
1300 * tty_driver_remove_tty() - remove a tty from the driver tables
1301 * @driver: the driver for the tty
1302 * @tty: tty to remove
1304 * Remove a tty object from the driver tables. The tty->index field will be set
1309 static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) in tty_driver_remove_tty() argument
1312 driver->ops->remove(driver, tty); in tty_driver_remove_tty()
1314 driver->ttys[tty->index] = NULL; in tty_driver_remove_tty()
1318 * tty_reopen() - fast re-open of an open tty
1319 * @tty: the tty to open
1326 static int tty_reopen(struct tty_struct *tty) in tty_reopen() argument
1328 struct tty_driver *driver = tty->driver; in tty_reopen()
1336 if (!tty->count) in tty_reopen()
1339 if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) in tty_reopen()
1342 ld = tty_ldisc_ref_wait(tty); in tty_reopen()
1346 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_reopen()
1350 if (!tty->ldisc) in tty_reopen()
1351 retval = tty_ldisc_reinit(tty, tty->termios.c_line); in tty_reopen()
1352 tty_ldisc_unlock(tty); in tty_reopen()
1356 tty->count++; in tty_reopen()
1362 * tty_init_dev - initialise a tty device
1363 * @driver: tty driver we are opening a device on
1366 * Prepare a tty device. This may not be a "new" clean device but could also be
1371 * tty struct or driver itself going away.
1373 * On exit the tty device has the line discipline attached and a reference
1374 * count of 1. If a pair was created for pty/tty use and the other was a pty
1380 * common) case of reopening a tty.
1382 * Return: new tty structure
1386 struct tty_struct *tty; in tty_init_dev() local
1392 * TTY is ready for operation, or else the table slots are vacated in tty_init_dev()
1400 tty = alloc_tty_struct(driver, idx); in tty_init_dev()
1401 if (!tty) { in tty_init_dev()
1406 tty_lock(tty); in tty_init_dev()
1407 retval = tty_driver_install_tty(driver, tty); in tty_init_dev()
1411 if (!tty->port) in tty_init_dev()
1412 tty->port = driver->ports[idx]; in tty_init_dev()
1414 if (WARN_RATELIMIT(!tty->port, in tty_init_dev()
1415 "%s: %s driver does not set tty->port. This would crash the kernel. Fix the driver!\n", in tty_init_dev()
1416 __func__, tty->driver->name)) { in tty_init_dev()
1421 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_init_dev()
1424 tty->port->itty = tty; in tty_init_dev()
1431 retval = tty_ldisc_setup(tty, tty->link); in tty_init_dev()
1434 tty_ldisc_unlock(tty); in tty_init_dev()
1435 /* Return the tty locked so that it cannot vanish under the caller */ in tty_init_dev()
1436 return tty; in tty_init_dev()
1439 tty_unlock(tty); in tty_init_dev()
1440 free_tty_struct(tty); in tty_init_dev()
1445 /* call the tty release_tty routine to clean out this slot */ in tty_init_dev()
1447 tty_ldisc_unlock(tty); in tty_init_dev()
1448 tty_info_ratelimited(tty, "ldisc open failed (%d), clearing slot %d\n", in tty_init_dev()
1451 tty_unlock(tty); in tty_init_dev()
1452 release_tty(tty, idx); in tty_init_dev()
1457 * tty_save_termios() - save tty termios data in driver table
1458 * @tty: tty whose termios data to save
1462 void tty_save_termios(struct tty_struct *tty) in tty_save_termios() argument
1465 int idx = tty->index; in tty_save_termios()
1468 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_save_termios()
1472 tp = tty->driver->termios[idx]; in tty_save_termios()
1477 tty->driver->termios[idx] = tp; in tty_save_termios()
1479 *tp = tty->termios; in tty_save_termios()
1484 * tty_flush_works - flush all works of a tty/pty pair
1485 * @tty: tty device to flush works for (or either end of a pty pair)
1487 * Sync flush all works belonging to @tty (and the 'other' tty).
1489 static void tty_flush_works(struct tty_struct *tty) in tty_flush_works() argument
1491 flush_work(&tty->SAK_work); in tty_flush_works()
1492 flush_work(&tty->hangup_work); in tty_flush_works()
1493 if (tty->link) { in tty_flush_works()
1494 flush_work(&tty->link->SAK_work); in tty_flush_works()
1495 flush_work(&tty->link->hangup_work); in tty_flush_works()
1500 * release_one_tty - release tty structure memory
1501 * @work: work of tty we are obliterating
1503 * Releases memory associated with a tty structure, and clears out the
1516 struct tty_struct *tty = in release_one_tty() local
1518 struct tty_driver *driver = tty->driver; in release_one_tty()
1521 if (tty->ops->cleanup) in release_one_tty()
1522 tty->ops->cleanup(tty); in release_one_tty()
1527 spin_lock(&tty->files_lock); in release_one_tty()
1528 list_del_init(&tty->tty_files); in release_one_tty()
1529 spin_unlock(&tty->files_lock); in release_one_tty()
1531 put_pid(tty->ctrl.pgrp); in release_one_tty()
1532 put_pid(tty->ctrl.session); in release_one_tty()
1533 free_tty_struct(tty); in release_one_tty()
1538 struct tty_struct *tty = container_of(kref, struct tty_struct, kref); in queue_release_one_tty() local
1543 INIT_WORK(&tty->hangup_work, release_one_tty); in queue_release_one_tty()
1544 schedule_work(&tty->hangup_work); in queue_release_one_tty()
1548 * tty_kref_put - release a tty kref
1549 * @tty: tty device
1551 * Release a reference to the @tty device and if need be let the kref layer
1554 void tty_kref_put(struct tty_struct *tty) in tty_kref_put() argument
1556 if (tty) in tty_kref_put()
1557 kref_put(&tty->kref, queue_release_one_tty); in tty_kref_put()
1562 * release_tty - release tty structure memory
1563 * @tty: tty device release
1564 * @idx: index of the tty device release
1566 * Release both @tty and a possible linked partner (think pty pair),
1574 static void release_tty(struct tty_struct *tty, int idx) in release_tty() argument
1577 WARN_ON(tty->index != idx); in release_tty()
1579 if (tty->ops->shutdown) in release_tty()
1580 tty->ops->shutdown(tty); in release_tty()
1581 tty_save_termios(tty); in release_tty()
1582 tty_driver_remove_tty(tty->driver, tty); in release_tty()
1583 if (tty->port) in release_tty()
1584 tty->port->itty = NULL; in release_tty()
1585 if (tty->link) in release_tty()
1586 tty->link->port->itty = NULL; in release_tty()
1587 if (tty->port) in release_tty()
1588 tty_buffer_cancel_work(tty->port); in release_tty()
1589 if (tty->link) in release_tty()
1590 tty_buffer_cancel_work(tty->link->port); in release_tty()
1592 tty_kref_put(tty->link); in release_tty()
1593 tty_kref_put(tty); in release_tty()
1597 * tty_release_checks - check a tty before real release
1598 * @tty: tty to check
1599 * @idx: index of the tty
1601 * Performs some paranoid checking before true release of the @tty. This is a
1604 static int tty_release_checks(struct tty_struct *tty, int idx) in tty_release_checks() argument
1607 if (idx < 0 || idx >= tty->driver->num) { in tty_release_checks()
1608 tty_debug(tty, "bad idx %d\n", idx); in tty_release_checks()
1613 if (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) in tty_release_checks()
1616 if (tty != tty->driver->ttys[idx]) { in tty_release_checks()
1617 tty_debug(tty, "bad driver table[%d] = %p\n", in tty_release_checks()
1618 idx, tty->driver->ttys[idx]); in tty_release_checks()
1621 if (tty->driver->other) { in tty_release_checks()
1622 struct tty_struct *o_tty = tty->link; in tty_release_checks()
1624 if (o_tty != tty->driver->other->ttys[idx]) { in tty_release_checks()
1625 tty_debug(tty, "bad other table[%d] = %p\n", in tty_release_checks()
1626 idx, tty->driver->other->ttys[idx]); in tty_release_checks()
1629 if (o_tty->link != tty) { in tty_release_checks()
1630 tty_debug(tty, "bad link = %p\n", o_tty->link); in tty_release_checks()
1639 * tty_kclose - closes tty opened by tty_kopen
1640 * @tty: tty device
1642 * Performs the final steps to release and free a tty device. It is the same as
1644 * @tty->port.
1646 void tty_kclose(struct tty_struct *tty) in tty_kclose() argument
1651 tty_ldisc_release(tty); in tty_kclose()
1653 /* Wait for pending work before tty destruction commences */ in tty_kclose()
1654 tty_flush_works(tty); in tty_kclose()
1656 tty_debug_hangup(tty, "freeing structure\n"); in tty_kclose()
1662 tty_port_set_kopened(tty->port, 0); in tty_kclose()
1663 release_tty(tty, tty->index); in tty_kclose()
1669 * tty_release_struct - release a tty struct
1670 * @tty: tty device
1671 * @idx: index of the tty
1673 * Performs the final steps to release and free a tty device. It is roughly the
1676 void tty_release_struct(struct tty_struct *tty, int idx) in tty_release_struct() argument
1681 tty_ldisc_release(tty); in tty_release_struct()
1683 /* Wait for pending work before tty destruction commmences */ in tty_release_struct()
1684 tty_flush_works(tty); in tty_release_struct()
1686 tty_debug_hangup(tty, "freeing structure\n"); in tty_release_struct()
1692 release_tty(tty, idx); in tty_release_struct()
1699 * @inode: inode of tty
1700 * @filp: file pointer for handle to tty
1702 * Called the last time each file handle is closed that references this tty.
1708 * Even releasing the tty structures is a tricky business. We have to be very
1717 struct tty_struct *tty = file_tty(filp); in tty_release() local
1724 if (tty_paranoia_check(tty, inode, __func__)) in tty_release()
1727 tty_lock(tty); in tty_release()
1728 check_tty_count(tty, __func__); in tty_release()
1732 idx = tty->index; in tty_release()
1733 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_release()
1734 tty->driver->subtype == PTY_TYPE_MASTER) in tty_release()
1735 o_tty = tty->link; in tty_release()
1737 if (tty_release_checks(tty, idx)) { in tty_release()
1738 tty_unlock(tty); in tty_release()
1742 tty_debug_hangup(tty, "releasing (count=%d)\n", tty->count); in tty_release()
1744 if (tty->ops->close) in tty_release()
1745 tty->ops->close(tty, filp); in tty_release()
1747 /* If tty is pty master, lock the slave pty (stable lock order) */ in tty_release()
1751 * Sanity check: if tty->count is going to zero, there shouldn't be in tty_release()
1752 * any waiters on tty->read_wait or tty->write_wait. We test the in tty_release()
1754 * close. This ensures that we won't block while releasing the tty in tty_release()
1766 if (tty->count <= 1) { in tty_release()
1767 if (waitqueue_active(&tty->read_wait)) { in tty_release()
1768 wake_up_poll(&tty->read_wait, EPOLLIN); in tty_release()
1771 if (waitqueue_active(&tty->write_wait)) { in tty_release()
1772 wake_up_poll(&tty->write_wait, EPOLLOUT); in tty_release()
1791 tty_warn(tty, "read/write wait queue active!\n"); in tty_release()
1802 tty_warn(tty, "bad slave count (%d)\n", o_tty->count); in tty_release()
1806 if (--tty->count < 0) { in tty_release()
1807 tty_warn(tty, "bad tty->count (%d)\n", tty->count); in tty_release()
1808 tty->count = 0; in tty_release()
1812 * We've decremented tty->count, so we need to remove this file in tty_release()
1813 * descriptor off the tty->tty_files list; this serves two in tty_release()
1816 * associated with this tty. in tty_release()
1826 * processes that still think tty or o_tty is their controlling in tty_release()
1827 * tty. in tty_release()
1829 if (!tty->count) { in tty_release()
1831 session_clear_tty(tty->ctrl.session); in tty_release()
1838 final = !tty->count && !(o_tty && o_tty->count); in tty_release()
1841 tty_unlock(tty); in tty_release()
1843 /* At this point, the tty->count == 0 should ensure a dead tty in tty_release()
1850 tty_debug_hangup(tty, "final close\n"); in tty_release()
1852 tty_release_struct(tty, idx); in tty_release()
1857 * tty_open_current_tty - get locked tty of current task
1859 * @filp: file pointer to tty
1860 * @return: locked tty of the current task iff @device is /dev/tty
1862 * Performs a re-open of the current task's controlling tty.
1869 struct tty_struct *tty; in tty_open_current_tty() local
1875 tty = get_current_tty(); in tty_open_current_tty()
1876 if (!tty) in tty_open_current_tty()
1879 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ in tty_open_current_tty()
1881 tty_lock(tty); in tty_open_current_tty()
1882 tty_kref_put(tty); /* safe to drop the kref now */ in tty_open_current_tty()
1884 retval = tty_reopen(tty); in tty_open_current_tty()
1886 tty_unlock(tty); in tty_open_current_tty()
1887 tty = ERR_PTR(retval); in tty_open_current_tty()
1889 return tty; in tty_open_current_tty()
1893 * tty_lookup_driver - lookup a tty driver for a given device file
1895 * @filp: file pointer to tty
1946 struct tty_struct *tty; in tty_kopen() local
1957 /* check whether we're reopening an existing tty */ in tty_kopen()
1958 tty = tty_driver_lookup_tty(driver, NULL, index); in tty_kopen()
1959 if (IS_ERR(tty) || shared) in tty_kopen()
1962 if (tty) { in tty_kopen()
1964 tty_kref_put(tty); in tty_kopen()
1965 tty = ERR_PTR(-EBUSY); in tty_kopen()
1966 } else { /* tty_init_dev returns tty with the tty_lock held */ in tty_kopen()
1967 tty = tty_init_dev(driver, index); in tty_kopen()
1968 if (IS_ERR(tty)) in tty_kopen()
1970 tty_port_set_kopened(tty->port, 1); in tty_kopen()
1975 return tty; in tty_kopen()
1979 * tty_kopen_exclusive - open a tty device for kernel
1982 * Opens tty exclusively for kernel. Performs the driver lookup, makes sure
1983 * it's not already opened and performs the first-time tty initialization.
1986 * * concurrent first-time tty initialization
1987 * * concurrent tty driver removal w/ lookup
1988 * * concurrent tty removal from driver table
1999 * tty_kopen_shared - open a tty device for shared in-kernel use
2002 * Opens an already existing tty for in-kernel use. Compared to
2014 * tty_open_by_driver - open a tty device
2016 * @filp: file pointer to tty
2019 * first-time tty initialization.
2023 * * concurrent first-time tty initialization
2024 * * concurrent tty driver removal w/ lookup
2025 * * concurrent tty removal from driver table
2032 struct tty_struct *tty; in tty_open_by_driver() local
2044 /* check whether we're reopening an existing tty */ in tty_open_by_driver()
2045 tty = tty_driver_lookup_tty(driver, filp, index); in tty_open_by_driver()
2046 if (IS_ERR(tty)) { in tty_open_by_driver()
2051 if (tty) { in tty_open_by_driver()
2052 if (tty_port_kopened(tty->port)) { in tty_open_by_driver()
2053 tty_kref_put(tty); in tty_open_by_driver()
2055 tty = ERR_PTR(-EBUSY); in tty_open_by_driver()
2059 retval = tty_lock_interruptible(tty); in tty_open_by_driver()
2060 tty_kref_put(tty); /* drop kref from tty_driver_lookup_tty() */ in tty_open_by_driver()
2064 tty = ERR_PTR(retval); in tty_open_by_driver()
2067 retval = tty_reopen(tty); in tty_open_by_driver()
2069 tty_unlock(tty); in tty_open_by_driver()
2070 tty = ERR_PTR(retval); in tty_open_by_driver()
2073 tty = tty_init_dev(driver, index); in tty_open_by_driver()
2078 return tty; in tty_open_by_driver()
2082 * tty_open - open a tty device
2084 * @filp: file pointer to tty
2086 * tty_open() and tty_release() keep up the tty count that contains the number
2087 * of opens done on a tty. We cannot use the inode-count, as different inodes
2088 * might point to the same tty.
2092 * (This is not done solely through tty->count, now. - Ted 1/27/92)
2098 * * %tty_mutex protects tty, tty_lookup_driver() and tty_init_dev().
2099 * * @tty->count should protect the rest.
2106 struct tty_struct *tty; in tty_open() local
2118 tty = tty_open_current_tty(device, filp); in tty_open()
2119 if (!tty) in tty_open()
2120 tty = tty_open_by_driver(device, filp); in tty_open()
2122 if (IS_ERR(tty)) { in tty_open()
2124 retval = PTR_ERR(tty); in tty_open()
2131 tty_add_file(tty, filp); in tty_open()
2133 check_tty_count(tty, __func__); in tty_open()
2134 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in tty_open()
2136 if (tty->ops->open) in tty_open()
2137 retval = tty->ops->open(tty, filp); in tty_open()
2143 tty_debug_hangup(tty, "open error %d, releasing\n", retval); in tty_open()
2145 tty_unlock(tty); /* need to call tty_release without BTM */ in tty_open()
2161 clear_bit(TTY_HUPPED, &tty->flags); in tty_open()
2166 (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_open()
2167 tty->driver->subtype == PTY_TYPE_MASTER); in tty_open()
2169 tty_open_proc_set_tty(filp, tty); in tty_open()
2170 tty_unlock(tty); in tty_open()
2176 * tty_poll - check tty status
2188 struct tty_struct *tty = file_tty(filp); in tty_poll() local
2192 if (tty_paranoia_check(tty, file_inode(filp), "tty_poll")) in tty_poll()
2195 ld = tty_ldisc_ref_wait(tty); in tty_poll()
2199 ret = ld->ops->poll(tty, filp, wait); in tty_poll()
2206 struct tty_struct *tty = file_tty(filp); in __tty_fasync() local
2210 if (tty_paranoia_check(tty, file_inode(filp), "tty_fasync")) in __tty_fasync()
2219 retval = fasync_helper(fd, filp, on, &tty->fasync); in __tty_fasync()
2227 spin_lock_irqsave(&tty->ctrl.lock, flags); in __tty_fasync()
2228 if (tty->ctrl.pgrp) { in __tty_fasync()
2229 pid = tty->ctrl.pgrp; in __tty_fasync()
2236 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in __tty_fasync()
2247 struct tty_struct *tty = file_tty(filp); in tty_fasync() local
2250 tty_lock(tty); in tty_fasync()
2253 tty_unlock(tty); in tty_fasync()
2261 * @tty: tty to fake input into
2264 * Fake input to a tty device. Does the necessary locking and input management.
2270 * * current->signal->tty check is safe without locks
2272 static int tiocsti(struct tty_struct *tty, u8 __user *p) in tiocsti() argument
2280 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) in tiocsti()
2284 tty_audit_tiocsti(tty, ch); in tiocsti()
2285 ld = tty_ldisc_ref_wait(tty); in tiocsti()
2288 tty_buffer_lock_exclusive(tty->port); in tiocsti()
2290 ld->ops->receive_buf(tty, &ch, NULL, 1); in tiocsti()
2291 tty_buffer_unlock_exclusive(tty->port); in tiocsti()
2298 * @tty: tty
2303 * Locking: @tty->winsize_mutex is taken to ensure the winsize data is
2306 static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocgwinsz() argument
2308 guard(mutex)(&tty->winsize_mutex); in tiocgwinsz()
2310 if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) in tiocgwinsz()
2318 * @tty: tty being resized
2324 int tty_do_resize(struct tty_struct *tty, struct winsize *ws) in tty_do_resize() argument
2328 guard(mutex)(&tty->winsize_mutex); in tty_do_resize()
2330 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in tty_do_resize()
2334 pgrp = tty_get_pgrp(tty); in tty_do_resize()
2339 tty->winsize = *ws; in tty_do_resize()
2347 * @tty: tty side of tty
2355 * Driver dependent. The default do_resize method takes the tty termios
2359 static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocswinsz() argument
2366 if (tty->ops->resize) in tiocswinsz()
2367 return tty->ops->resize(tty, &tmp_ws); in tiocswinsz()
2369 return tty_do_resize(tty, &tmp_ws); in tiocswinsz()
2414 * @tty: tty device
2421 static int tiocsetd(struct tty_struct *tty, int __user *p) in tiocsetd() argument
2429 ret = tty_set_ldisc(tty, disc); in tiocsetd()
2436 * @tty: tty device
2442 * or the @tty is being hungup)
2444 static int tiocgetd(struct tty_struct *tty, int __user *p) in tiocgetd() argument
2449 ld = tty_ldisc_ref_wait(tty); in tiocgetd()
2459 * @tty: device to break on
2466 * @tty->atomic_write_lock serializes
2468 static int send_break(struct tty_struct *tty, unsigned int duration) in send_break() argument
2472 if (tty->ops->break_ctl == NULL) in send_break()
2475 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK) in send_break()
2476 return tty->ops->break_ctl(tty, duration); in send_break()
2479 if (tty_write_lock(tty, false) < 0) in send_break()
2482 retval = tty->ops->break_ctl(tty, -1); in send_break()
2485 retval = tty->ops->break_ctl(tty, 0); in send_break()
2490 tty_write_unlock(tty); in send_break()
2500 * @tty: tty device
2502 * Obtain the modem status bits from the tty driver if the feature
2505 int tty_get_tiocm(struct tty_struct *tty) in tty_get_tiocm() argument
2509 if (tty->ops->tiocmget) in tty_get_tiocm()
2510 retval = tty->ops->tiocmget(tty); in tty_get_tiocm()
2518 * @tty: tty device
2521 * Obtain the modem status bits from the tty driver if the feature is
2526 static int tty_tiocmget(struct tty_struct *tty, int __user *p) in tty_tiocmget() argument
2530 retval = tty_get_tiocm(tty); in tty_tiocmget()
2539 * @tty: tty device
2543 * Set the modem status bits from the tty driver if the feature
2548 static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd, in tty_tiocmset() argument
2554 if (tty->ops->tiocmset == NULL) in tty_tiocmset()
2575 return tty->ops->tiocmset(tty, set, clear); in tty_tiocmset()
2579 * tty_get_icount - get tty statistics
2580 * @tty: tty device
2583 * Gets a copy of the @tty's icount statistics.
2587 int tty_get_icount(struct tty_struct *tty, in tty_get_icount() argument
2592 if (tty->ops->get_icount) in tty_get_icount()
2593 return tty->ops->get_icount(tty, icount); in tty_get_icount()
2599 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) in tty_tiocgicount() argument
2604 retval = tty_get_icount(tty, &icount); in tty_tiocgicount()
2613 static int tty_set_serial(struct tty_struct *tty, struct serial_struct *ss) in tty_set_serial() argument
2623 if (!tty->ops->set_serial) in tty_set_serial()
2626 return tty->ops->set_serial(tty, ss); in tty_set_serial()
2629 static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocsserial() argument
2636 return tty_set_serial(tty, &v); in tty_tiocsserial()
2639 static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocgserial() argument
2645 if (!tty->ops->get_serial) in tty_tiocgserial()
2647 err = tty->ops->get_serial(tty, &v); in tty_tiocgserial()
2657 static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) in tty_pair_get_tty() argument
2659 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_pair_get_tty()
2660 tty->driver->subtype == PTY_TYPE_MASTER) in tty_pair_get_tty()
2661 tty = tty->link; in tty_pair_get_tty()
2662 return tty; in tty_pair_get_tty()
2670 struct tty_struct *tty = file_tty(file); in tty_ioctl() local
2676 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_ioctl()
2679 real_tty = tty_pair_get_tty(tty); in tty_ioctl()
2690 retval = tty_check_change(tty); in tty_ioctl()
2694 tty_wait_until_sent(tty, 0); in tty_ioctl()
2706 return tiocsti(tty, p); in tty_ioctl()
2712 return real_tty != tty ? -EINVAL : tioccons(file); in tty_ioctl()
2714 set_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2717 clear_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2721 int excl = test_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2726 return tiocgetd(tty, p); in tty_ioctl()
2728 return tiocsetd(tty, p); in tty_ioctl()
2732 tty_vhangup(tty); in tty_ioctl()
2744 if (tty->ops->break_ctl) in tty_ioctl()
2745 return tty->ops->break_ctl(tty, -1); in tty_ioctl()
2748 if (tty->ops->break_ctl) in tty_ioctl()
2749 return tty->ops->break_ctl(tty, 0); in tty_ioctl()
2757 return send_break(tty, 250); in tty_ioctl()
2760 return send_break(tty, arg ? arg*100 : 250); in tty_ioctl()
2763 return tty_tiocmget(tty, p); in tty_ioctl()
2767 return tty_tiocmset(tty, cmd, p); in tty_ioctl()
2769 return tty_tiocgicount(tty, p); in tty_ioctl()
2774 /* flush tty buffer and allow ldisc to process ioctl */ in tty_ioctl()
2775 tty_buffer_flush(tty, NULL); in tty_ioctl()
2780 return tty_tiocsserial(tty, p); in tty_ioctl()
2782 return tty_tiocgserial(tty, p); in tty_ioctl()
2785 return ptm_open_peer(file, tty, (int)arg); in tty_ioctl()
2787 retval = tty_jobctrl_ioctl(tty, real_tty, file, cmd, arg); in tty_ioctl()
2791 if (tty->ops->ioctl) { in tty_ioctl()
2792 retval = tty->ops->ioctl(tty, cmd, arg); in tty_ioctl()
2796 ld = tty_ldisc_ref_wait(tty); in tty_ioctl()
2801 retval = ld->ops->ioctl(tty, cmd, arg); in tty_ioctl()
2833 static int compat_tty_tiocsserial(struct tty_struct *tty, in compat_tty_tiocsserial() argument
2848 return tty_set_serial(tty, &v); in compat_tty_tiocsserial()
2851 static int compat_tty_tiocgserial(struct tty_struct *tty, in compat_tty_tiocgserial() argument
2861 if (!tty->ops->get_serial) in compat_tty_tiocgserial()
2863 err = tty->ops->get_serial(tty, &v); in compat_tty_tiocgserial()
2878 struct tty_struct *tty = file_tty(file); in tty_compat_ioctl() local
2961 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_compat_ioctl()
2966 return compat_tty_tiocsserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2968 return compat_tty_tiocgserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2970 if (tty->ops->compat_ioctl) { in tty_compat_ioctl()
2971 retval = tty->ops->compat_ioctl(tty, cmd, arg); in tty_compat_ioctl()
2976 ld = tty_ldisc_ref_wait(tty); in tty_compat_ioctl()
2980 retval = ld->ops->compat_ioctl(tty, cmd, arg); in tty_compat_ioctl()
2982 retval = ld->ops->ioctl(tty, (unsigned long)compat_ptr(cmd), in tty_compat_ioctl()
3000 * tty when the user hits the "Secure Attention Key". Required for
3006 * with the current tty must be dead before the new getty is allowed
3016 void __do_SAK(struct tty_struct *tty) in __do_SAK() argument
3022 scoped_guard(spinlock_irqsave, &tty->ctrl.lock) in __do_SAK()
3023 session = get_pid(tty->ctrl.session); in __do_SAK()
3025 tty_ldisc_flush(tty); in __do_SAK()
3027 tty_driver_flush_buffer(tty); in __do_SAK()
3032 tty_notice(tty, "SAK: killed process %d (%s): by session\n", in __do_SAK()
3037 /* Now kill any processes that happen to have the tty open */ in __do_SAK()
3039 if (p->signal->tty == tty) { in __do_SAK()
3040 tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", in __do_SAK()
3047 i = iterate_fd(p->files, 0, this_tty, tty); in __do_SAK()
3049 tty_notice(tty, "SAK: killed process %d (%s): by fd#%d\n", in __do_SAK()
3061 struct tty_struct *tty = in do_SAK_work() local
3063 __do_SAK(tty); in do_SAK_work()
3067 * The tq handling here is a little racy - tty->SAK_work may already be queued.
3072 void do_SAK(struct tty_struct *tty) in do_SAK() argument
3074 if (!tty) in do_SAK()
3076 schedule_work(&tty->SAK_work); in do_SAK()
3081 static struct device *tty_get_device(struct tty_struct *tty) in tty_get_device() argument
3083 dev_t devt = tty_devnum(tty); in tty_get_device()
3090 * alloc_tty_struct - allocate a new tty
3091 * @driver: driver which will handle the returned tty
3092 * @idx: minor of the tty
3094 * This subroutine allocates and initializes a tty structure.
3096 * Locking: none - @tty in question is not exposed at this point
3100 struct tty_struct *tty; in alloc_tty_struct() local
3102 tty = kzalloc_obj(*tty, GFP_KERNEL_ACCOUNT); in alloc_tty_struct()
3103 if (!tty) in alloc_tty_struct()
3106 kref_init(&tty->kref); in alloc_tty_struct()
3107 if (tty_ldisc_init(tty)) { in alloc_tty_struct()
3108 kfree(tty); in alloc_tty_struct()
3111 tty->ctrl.session = NULL; in alloc_tty_struct()
3112 tty->ctrl.pgrp = NULL; in alloc_tty_struct()
3113 mutex_init(&tty->legacy_mutex); in alloc_tty_struct()
3114 mutex_init(&tty->throttle_mutex); in alloc_tty_struct()
3115 init_rwsem(&tty->termios_rwsem); in alloc_tty_struct()
3116 mutex_init(&tty->winsize_mutex); in alloc_tty_struct()
3117 init_ldsem(&tty->ldisc_sem); in alloc_tty_struct()
3118 init_waitqueue_head(&tty->write_wait); in alloc_tty_struct()
3119 init_waitqueue_head(&tty->read_wait); in alloc_tty_struct()
3120 INIT_WORK(&tty->hangup_work, do_tty_hangup); in alloc_tty_struct()
3121 mutex_init(&tty->atomic_write_lock); in alloc_tty_struct()
3122 spin_lock_init(&tty->ctrl.lock); in alloc_tty_struct()
3123 spin_lock_init(&tty->flow.lock); in alloc_tty_struct()
3124 spin_lock_init(&tty->files_lock); in alloc_tty_struct()
3125 INIT_LIST_HEAD(&tty->tty_files); in alloc_tty_struct()
3126 INIT_WORK(&tty->SAK_work, do_SAK_work); in alloc_tty_struct()
3128 tty->driver = driver; in alloc_tty_struct()
3129 tty->ops = driver->ops; in alloc_tty_struct()
3130 tty->index = idx; in alloc_tty_struct()
3131 tty_line_name(driver, idx, tty->name); in alloc_tty_struct()
3132 tty->dev = tty_get_device(tty); in alloc_tty_struct()
3134 return tty; in alloc_tty_struct()
3138 * tty_put_char - write one character to a tty
3139 * @tty: tty
3142 * Write one byte to the @tty using the provided @tty->ops->put_char() method
3150 int tty_put_char(struct tty_struct *tty, u8 ch) in tty_put_char() argument
3152 if (tty->ops->put_char) in tty_put_char()
3153 return tty->ops->put_char(tty, ch); in tty_put_char()
3154 return tty->ops->write(tty, &ch, 1); in tty_put_char()
3176 * tty_register_device - register a tty device
3177 * @driver: the tty driver that describes the tty device
3178 * @index: the index in the tty driver for this tty device
3179 * @device: a struct device that is associated with this tty device.
3181 * for this tty device it can be set to NULL safely.
3183 * This call is required to be made to register an individual tty device
3184 * if the tty driver's flags have the %TTY_DRIVER_DYNAMIC_DEV bit set. If
3185 * that bit is not set, this function should not be called by a tty
3190 * Return: A pointer to the struct device for this tty device (or
3207 * tty_register_device_attr - register a tty device
3208 * @driver: the tty driver that describes the tty device
3209 * @index: the index in the tty driver for this tty device
3210 * @device: a struct device that is associated with this tty device.
3212 * for this tty device it can be set to %NULL safely.
3216 * This call is required to be made to register an individual tty device if the
3217 * tty driver's flags have the %TTY_DRIVER_DYNAMIC_DEV bit set. If that bit is
3218 * not set, this function should not be called by a tty driver.
3222 * Return: A pointer to the struct device for this tty device (or
3237 pr_err("%s: Attempt to register invalid tty line number (%d)\n", in tty_register_device_attr()
3296 * tty_unregister_device - unregister a tty device
3297 * @driver: the tty driver that describes the tty device
3298 * @index: the index in the tty driver for this tty device
3300 * If a tty device is registered with a call to tty_register_device() then
3301 * this function must be called when the tty device is gone.
3316 * __tty_alloc_driver - allocate tty driver
3408 * tty_driver_kref_put - drop a reference to a tty driver
3420 * tty_register_driver - register a tty driver
3423 * Called by a tty driver to register itself.
3483 * tty_unregister_driver - unregister a tty driver
3486 * Called by a tty driver to unregister itself.
3497 dev_t tty_devnum(struct tty_struct *tty) in tty_devnum() argument
3499 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; in tty_devnum()
3519 .name = "tty",
3623 * Ok, now we can initialize the rest of the tty devices and can count
3628 register_sysctl_init("dev/tty", tty_table); in tty_init()
3631 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) in tty_init()
3632 panic("Couldn't register /dev/tty driver\n"); in tty_init()
3633 device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); in tty_init()