Skip to content

Commit 9b06703

Browse files
author
Al Viro
committed
switch drivers/net/tun.c to ->read_iter()
Signed-off-by: Al Viro <[email protected]>
1 parent 7eab8d9 commit 9b06703

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

drivers/net/tun.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,18 +1339,17 @@ static ssize_t tun_put_user(struct tun_struct *tun,
13391339
}
13401340

13411341
static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1342-
const struct iovec *iv, unsigned long segs,
1343-
ssize_t len, int noblock)
1342+
struct iov_iter *to,
1343+
int noblock)
13441344
{
13451345
struct sk_buff *skb;
1346-
ssize_t ret = 0;
1346+
ssize_t ret;
13471347
int peeked, err, off = 0;
1348-
struct iov_iter iter;
13491348

13501349
tun_debug(KERN_INFO, tun, "tun_do_read\n");
13511350

1352-
if (!len)
1353-
return ret;
1351+
if (!iov_iter_count(to))
1352+
return 0;
13541353

13551354
if (tun->dev->reg_state != NETREG_REGISTERED)
13561355
return -EIO;
@@ -1359,37 +1358,27 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
13591358
skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0,
13601359
&peeked, &off, &err);
13611360
if (!skb)
1362-
return ret;
1361+
return 0;
13631362

1364-
iov_iter_init(&iter, READ, iv, segs, len);
1365-
ret = tun_put_user(tun, tfile, skb, &iter);
1363+
ret = tun_put_user(tun, tfile, skb, to);
13661364
kfree_skb(skb);
13671365

13681366
return ret;
13691367
}
13701368

1371-
static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv,
1372-
unsigned long count, loff_t pos)
1369+
static ssize_t tun_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
13731370
{
13741371
struct file *file = iocb->ki_filp;
13751372
struct tun_file *tfile = file->private_data;
13761373
struct tun_struct *tun = __tun_get(tfile);
1377-
ssize_t len, ret;
1374+
ssize_t len = iov_iter_count(to), ret;
13781375

13791376
if (!tun)
13801377
return -EBADFD;
1381-
len = iov_length(iv, count);
1382-
if (len < 0) {
1383-
ret = -EINVAL;
1384-
goto out;
1385-
}
1386-
1387-
ret = tun_do_read(tun, tfile, iv, count, len,
1388-
file->f_flags & O_NONBLOCK);
1378+
ret = tun_do_read(tun, tfile, to, file->f_flags & O_NONBLOCK);
13891379
ret = min_t(ssize_t, ret, len);
13901380
if (ret > 0)
13911381
iocb->ki_pos = ret;
1392-
out:
13931382
tun_put(tun);
13941383
return ret;
13951384
}
@@ -1471,6 +1460,7 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
14711460
{
14721461
struct tun_file *tfile = container_of(sock, struct tun_file, socket);
14731462
struct tun_struct *tun = __tun_get(tfile);
1463+
struct iov_iter to;
14741464
int ret;
14751465

14761466
if (!tun)
@@ -1485,8 +1475,8 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
14851475
SOL_PACKET, TUN_TX_TIMESTAMP);
14861476
goto out;
14871477
}
1488-
ret = tun_do_read(tun, tfile, m->msg_iov, m->msg_iovlen, total_len,
1489-
flags & MSG_DONTWAIT);
1478+
iov_iter_init(&to, READ, m->msg_iov, m->msg_iovlen, total_len);
1479+
ret = tun_do_read(tun, tfile, &to, flags & MSG_DONTWAIT);
14901480
if (ret > total_len) {
14911481
m->msg_flags |= MSG_TRUNC;
14921482
ret = flags & MSG_TRUNC ? ret : total_len;
@@ -2242,8 +2232,8 @@ static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
22422232
static const struct file_operations tun_fops = {
22432233
.owner = THIS_MODULE,
22442234
.llseek = no_llseek,
2245-
.read = do_sync_read,
2246-
.aio_read = tun_chr_aio_read,
2235+
.read = new_sync_read,
2236+
.read_iter = tun_chr_read_iter,
22472237
.write = do_sync_write,
22482238
.aio_write = tun_chr_aio_write,
22492239
.poll = tun_chr_poll,

0 commit comments

Comments
 (0)