drivers/tty/tty_ldisc.c
Source file repositories/reference/linux-study-clean/drivers/tty/tty_ldisc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/tty_ldisc.c- Extension
.c- Size
- 20841 bytes
- Lines
- 825
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/errno.hlinux/kmod.hlinux/sched.hlinux/interrupt.hlinux/tty.hlinux/tty_driver.hlinux/file.hlinux/mm.hlinux/string.hlinux/slab.hlinux/poll.hlinux/proc_fs.hlinux/module.hlinux/device.hlinux/wait.hlinux/bitops.hlinux/seq_file.hlinux/uaccess.hlinux/ratelimit.htty.h
Detected Declarations
function tty_register_ldiscfunction tty_unregister_ldiscfunction put_ldopsfunction tty_ldisc_getfunction tty_ldiscs_seq_stopfunction tty_ldisc_reffunction __tty_ldisc_lockfunction __tty_ldisc_lock_nestedfunction __tty_ldisc_unlockfunction tty_ldisc_lockfunction tty_ldisc_unlockfunction tty_ldisc_lock_pair_timeoutfunction tty_ldisc_lock_pairfunction tty_ldisc_unlock_pairfunction queuefunction tty_set_termios_ldiscfunction tty_ldisc_openfunction tty_ldisc_closefunction tty_ldisc_failtofunction tty_ldisc_restorefunction changefunction tty_ldisc_killfunction tty_reset_termiosfunction tty_ldisc_reinitfunction closefunction tty_ldisc_setupfunction tty_ldisc_releasefunction tty_ldisc_initfunction upexport tty_register_ldiscexport tty_unregister_ldiscexport tty_ldisc_ref_waitexport tty_ldisc_refexport tty_ldisc_derefexport tty_ldisc_flushexport tty_set_ldisc
Annotated Snippet
if (ret) {
ret = __tty_ldisc_lock_nested(tty2, timeout);
if (!ret)
__tty_ldisc_unlock(tty);
}
} else {
/* if this is possible, it has lots of implications */
WARN_ON_ONCE(tty == tty2);
if (tty2 && tty != tty2) {
ret = __tty_ldisc_lock(tty2, timeout);
if (ret) {
ret = __tty_ldisc_lock_nested(tty, timeout);
if (!ret)
__tty_ldisc_unlock(tty2);
}
} else
ret = __tty_ldisc_lock(tty, timeout);
}
if (!ret)
return -EBUSY;
set_bit(TTY_LDISC_HALTED, &tty->flags);
if (tty2)
set_bit(TTY_LDISC_HALTED, &tty2->flags);
return 0;
}
static void tty_ldisc_lock_pair(struct tty_struct *tty, struct tty_struct *tty2)
{
tty_ldisc_lock_pair_timeout(tty, tty2, MAX_SCHEDULE_TIMEOUT);
}
static void tty_ldisc_unlock_pair(struct tty_struct *tty,
struct tty_struct *tty2)
{
__tty_ldisc_unlock(tty);
if (tty2)
__tty_ldisc_unlock(tty2);
}
/**
* tty_ldisc_flush - flush line discipline queue
* @tty: tty to flush ldisc for
*
* Flush the line discipline queue (if any) and the tty flip buffers for this
* @tty.
*/
void tty_ldisc_flush(struct tty_struct *tty)
{
struct tty_ldisc *ld = tty_ldisc_ref(tty);
tty_buffer_flush(tty, ld);
if (ld)
tty_ldisc_deref(ld);
}
EXPORT_SYMBOL_GPL(tty_ldisc_flush);
/**
* tty_set_termios_ldisc - set ldisc field
* @tty: tty structure
* @disc: line discipline number
*
* This is probably overkill for real world processors but they are not on hot
* paths so a little discipline won't do any harm.
*
* The line discipline-related tty_struct fields are reset to prevent the ldisc
* driver from re-using stale information for the new ldisc instance.
*
* Locking: takes termios_rwsem
*/
static void tty_set_termios_ldisc(struct tty_struct *tty, int disc)
{
down_write(&tty->termios_rwsem);
tty->termios.c_line = disc;
up_write(&tty->termios_rwsem);
tty->disc_data = NULL;
tty->receive_room = 0;
}
/**
* tty_ldisc_open - open a line discipline
* @tty: tty we are opening the ldisc on
* @ld: discipline to open
*
* A helper opening method. Also a convenient debugging and check point.
*
* Locking: always called with BTM already held.
*/
Annotation
- Immediate include surface: `linux/types.h`, `linux/errno.h`, `linux/kmod.h`, `linux/sched.h`, `linux/interrupt.h`, `linux/tty.h`, `linux/tty_driver.h`, `linux/file.h`.
- Detected declarations: `function tty_register_ldisc`, `function tty_unregister_ldisc`, `function put_ldops`, `function tty_ldisc_get`, `function tty_ldiscs_seq_stop`, `function tty_ldisc_ref`, `function __tty_ldisc_lock`, `function __tty_ldisc_lock_nested`, `function __tty_ldisc_unlock`, `function tty_ldisc_lock`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.