Even we may not care whether some ttydevsw_* calls succeed or not,
every of such calls may drop t_mtx and the tty state may change.
That is particularly true for USB-based drivers such as umodem.
Then, every ttydevsw_* dispatch function asserts that the terminal is
not gone.
Those things combined may lead to triggering the assert with
INVARIANTS-enabled kernel.
Example:
panic: Assertion !tty_gone(tp) failed at /usr/src/sys/sys/ttydevsw.h:165 cpuid = 3 time = 1780348587 KDB: stack backtrace: db_trace_self_wrapper() at 0xffffffff80647b3b = db_trace_self_wrapper+0x2b/frame 0xfffffe059c07f730 kdb_backtrace() at 0xffffffff809d12e7 = kdb_backtrace+0x37/frame 0xfffffe059c07f7e0 vpanic() at 0xffffffff809803b9 = vpanic+0x169/frame 0xfffffe059c07f920 panic() at 0xffffffff80980193 = panic+0x43/frame 0xfffffe059c07f980 ttydevsw_modem() at 0xffffffff80a0f2e7 = ttydevsw_modem+0x37/frame 0xfffffe059c07f990 ttydev_open() at 0xffffffff80a0e7ba = ttydev_open+0x2ba/frame 0xfffffe059c07f9e0 devfs_open() at 0xffffffff80818e49 = devfs_open+0x129/frame 0xfffffe059c07fa40 VOP_OPEN_APV() at 0xffffffff80dbb403 = VOP_OPEN_APV+0x93/frame 0xfffffe059c07fa70 vn_open_vnode() at 0xffffffff80a890b1 = vn_open_vnode+0x1e1/frame 0xfffffe059c07fb20 vn_open_cred() at 0xffffffff80a88a6c = vn_open_cred+0x58c/frame 0xfffffe059c07fc90 openatfp() at 0xffffffff80a7ef47 = openatfp+0x257/frame 0xfffffe059c07fdd0 sys_openat() at 0xffffffff80a7eccd = sys_openat+0x3d/frame 0xfffffe059c07fe00 amd64_syscall() at 0xffffffff80d2816b = amd64_syscall+0x18b/frame 0xfffffe059c07ff30 fast_syscall_common() at 0xffffffff80cfd54b = fast_syscall_common+0xf8/frame 0xfffffe059c07ff30 --- syscall (499, FreeBSD ELF64, openat), rip = 0x82523a41a, rsp = 0x8209237b8, rbp = 0x820923830 ---
Additionally, ttydev_open could return success for an already gone TTY.
Not sure if that was a problem.
I am not fond of this approach to fixing the issue.
In my opinion, it may be better to change ttydevsw_* to check tty_gone
and return ENXIO instead of asserting.
With the asynchronous nature of USB and a peripheral disconnect not
being unlikely, it's hard or even pointless to keep the assert working.