Revert "tun: remove useless codes in tun_chr_aio_read() and tun_recvmsg()"
authorDavid S. Miller <davem@davemloft.net>
Wed, 11 Dec 2013 03:05:45 +0000 (22:05 -0500)
committerDavid S. Miller <davem@davemloft.net>
Wed, 11 Dec 2013 03:05:45 +0000 (22:05 -0500)
This reverts commit 73713357ab58aacda1af715bb5a623528dbbfd79.

MSG_TRUNC handling was broken and is going to be fixed in
the 'net' tree, so revert this.

Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c

index bbb693512918e17a77e6a3ea06f9c875b6f17861..3c5a8d8cde5077bc0c2d39d2f0aadc4e7d4a6231 100644 (file)
@@ -1354,6 +1354,7 @@ static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv,
 
        ret = tun_do_read(tun, tfile, iv, len,
                          file->f_flags & O_NONBLOCK);
+       ret = min_t(ssize_t, ret, len);
        if (ret > 0)
                iocb->ki_pos = ret;
 out:
@@ -1454,6 +1455,10 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
        }
        ret = tun_do_read(tun, tfile, m->msg_iov, total_len,
                          flags & MSG_DONTWAIT);
+       if (ret > total_len) {
+               m->msg_flags |= MSG_TRUNC;
+               ret = flags & MSG_TRUNC ? ret : total_len;
+       }
 out:
        tun_put(tun);
        return ret;