]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
um: tty: Fix handling of close in tty lines
authorAnton Ivanov <anton.ivanov@cambridgegreys.com>
Mon, 7 Dec 2020 17:19:39 +0000 (17:19 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 20 Jan 2021 13:26:08 +0000 (14:26 +0100)
BugLink: https://bugs.launchpad.net/bugs/1910822
[ Upstream commit 9b1c0c0e25dcccafd30e7d4c150c249cc65550eb ]

Fix a logical error in tty reading. We get 0 and errno == EAGAIN
on the first attempt to read from a closed file descriptor.

Compared to that a true EAGAIN is EAGAIN and -1.

If we check errno for EAGAIN first, before checking the return
value we miss the fact that the descriptor is closed.

This bug is as old as the driver. It was not showing up with
the original POLL based IRQ controller, because it was
producing multiple events. Switching to EPOLL unmasked it.

Fixes: ff6a17989c08 ("Epoll based IRQ controller")
Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
arch/um/drivers/chan_user.c

index 4d80526a4236e69113c102dbcc95b9fe3195fa24..d8845d4aac6a75be257c3b5f825fb77947edcd80 100644 (file)
@@ -26,10 +26,10 @@ int generic_read(int fd, char *c_out, void *unused)
        n = read(fd, c_out, sizeof(*c_out));
        if (n > 0)
                return n;
-       else if (errno == EAGAIN)
-               return 0;
        else if (n == 0)
                return -EIO;
+       else if (errno == EAGAIN)
+               return 0;
        return -errno;
 }