[PATCH 3/3] tty: n_hdlc: fix read() hangup check

From: Johan Hovold

Date: Wed Oct 28 2026 - 09:26:03 EST


When a tty is hung up, the file ops are generally set to
hung_up_tty_fops, but this is not the case for, for example,
/dev/console.

Make sure to check the TTY_HUPPING flag so that a hangup is detected and
read() returns zero also with /dev/console (as is done for n_tty [1]).

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 readers, but since then
read() incorrectly returns -EAGAIN instead.

The false-positive stuck hangup issue was flagged by an LLM.

[1] 28b0f8a6962a ("tty: make n_tty_read() always abort if hangup is in progress")

Fixes: 1035b63d3c6f ("n_hdlc: fix read and write locking")
Cc: stable@xxxxxxxxxxxxxxx # 2.6.38
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/tty/n_hdlc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 02676ae9b112..1a3a276f2db3 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -437,7 +437,8 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
ret = -EIO;
break;
}
- if (tty_hung_up_p(file))
+
+ if (tty_hung_up_p(file) || test_bit(TTY_HUPPING, &tty->flags))
break;

rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
--
2.55.0