[PATCH 1/3] tty: n_hdlc: fix missing write() hangup check
From: Johan Hovold
Date: Wed Oct 28 2026 - 09:25:01 EST
Add the missing hangup check to the n_hdlc write() wait loop so that
hangups are detected and -EIO is returned as expected.
Note that before commit c96cf923a98d ("tty: Don't block on IO when ldisc
change is pending") a task hanging up the tty would get stuck in
uninterruptible sleep when there are blocked writers, but since then
write() incorrectly returns -EAGAIN instead.
The false-positive stuck hangup issue was flagged by an LLM.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/tty/n_hdlc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 895b850a5950..0fbc44968a44 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -529,6 +529,11 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
+ if (tty_hung_up_p(file)) {
+ error = -EIO;
+ break;
+ }
+
tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
if (tbuf)
break;
--
2.55.0