tty_port_tty_get(9)
π tty_port_tty_get(9) β a Kernel API Manual moment
okay bestie, welcome to the Kernel API Manual, section 9, and the star of the show is tty_port_tty_get π lowkey one of the most useful little functions in the tty world and I need you to know about it.
β¨ NAME β¨
tty_port_tty_get β get a tty reference π«Ά like literally just grab one, safely.
πΈ SYNOPSIS πΈ
struct tty_struct * tty_port_tty_get (struct tty_port *port );
that's it. that's the whole vibe. one function, one pointer in, one pointer out π
π¦ ARGUMENTS π¦
portβ the tty port, bestie. that's the thing you're passing in. the port itself. π
π₯ DESCRIPTION π₯
okay so here's the tea β β this function returns a refcount protected tty instance. meaning it hands you a tty and it's already got its refcount situation handled for you, no cap. responsible queen behavior π
and if the port is not associated with a tty? you get NULL. that happens, like, when the port has been closed or hung up (eg due to close or hangup). so yes, NULL is a real possible answer and you should be checking for it, ngl π
fr fr β don't just assume you're getting a tty back. check your return value, it's giving basic safety and it's iconic π
π SEE ALSO π
the kernel file lives at ./drivers/tty/tty_port.c and here's the whole friend group, all 24 of them, in the exact order they were introduced to me π§:
tty_port_init(9)tty_port_link_wq(9)tty_port_link_device(9)tty_port_register_device(9)tty_port_register_device_attr(9)tty_port_register_device_attr_serdev(9)tty_port_unregister_device(9)tty_port_destroy(9)tty_port_put(9)tty_port_tty_set(9)tty_port_shutdown(9)tty_port_hangup(9)tty_port_tty_hangup(9)tty_port_tty_vhangup(9)tty_port_tty_wakeup(9)tty_port_carrier_raised(9)tty_port_raise_dtr_rts(9)tty_port_lower_dtr_rts(9)tty_port_block_til_ready(9)tty_port_close_start(9)tty_port_close_end(9)tty_port_close(9)tty_port_install(9)tty_port_open(9)
mwah π that's the page. go get your refcount-protected tty and slay.
sign-off time π β this one comes from ./drivers/tty, dated October 2026, and it's page tty_port_tty_get(9). periodt. π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms