tun: fix blocking read [Linux 5.0]

tun: fix blocking read [Linux 5.0]

This Linux kernel change "tun: fix blocking read" is included in the Linux 5.0 release. This change is authored by Timur Celik <mail [at] timurcelik.de> on Sat Feb 23 12:53:13 2019 +0100. The commit for this change in Linux stable tree is 71828b2 (patch).

tun: fix blocking read

This patch moves setting of the current state into the loop. Otherwise
the task may end up in a busy wait loop if none of the break conditions
are met.

Signed-off-by: Timur Celik <[email protected]>
Signed-off-by: David S. Miller <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/tun.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index fed298c..d291762 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2167,9 +2167,9 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err)

    add_wait_queue(&tfile->wq.wait, &wait);
-   current->state = TASK_INTERRUPTIBLE;

    while (1) {
+       set_current_state(TASK_INTERRUPTIBLE);
        ptr = ptr_ring_consume(&tfile->tx_ring);
        if (ptr)
@@ -2185,7 +2185,7 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err)

-   current->state = TASK_RUNNING;
+   set_current_state(TASK_RUNNING);
    remove_wait_queue(&tfile->wq.wait, &wait);


Leave a Reply

Your email address will not be published. Required fields are marked *