@@ -1339,18 +1339,17 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1339
1339
}
1340
1340
1341
1341
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 )
1344
1344
{
1345
1345
struct sk_buff * skb ;
1346
- ssize_t ret = 0 ;
1346
+ ssize_t ret ;
1347
1347
int peeked , err , off = 0 ;
1348
- struct iov_iter iter ;
1349
1348
1350
1349
tun_debug (KERN_INFO , tun , "tun_do_read\n" );
1351
1350
1352
- if (!len )
1353
- return ret ;
1351
+ if (!iov_iter_count ( to ) )
1352
+ return 0 ;
1354
1353
1355
1354
if (tun -> dev -> reg_state != NETREG_REGISTERED )
1356
1355
return - EIO ;
@@ -1359,37 +1358,27 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1359
1358
skb = __skb_recv_datagram (tfile -> socket .sk , noblock ? MSG_DONTWAIT : 0 ,
1360
1359
& peeked , & off , & err );
1361
1360
if (!skb )
1362
- return ret ;
1361
+ return 0 ;
1363
1362
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 );
1366
1364
kfree_skb (skb );
1367
1365
1368
1366
return ret ;
1369
1367
}
1370
1368
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 )
1373
1370
{
1374
1371
struct file * file = iocb -> ki_filp ;
1375
1372
struct tun_file * tfile = file -> private_data ;
1376
1373
struct tun_struct * tun = __tun_get (tfile );
1377
- ssize_t len , ret ;
1374
+ ssize_t len = iov_iter_count ( to ) , ret ;
1378
1375
1379
1376
if (!tun )
1380
1377
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 );
1389
1379
ret = min_t (ssize_t , ret , len );
1390
1380
if (ret > 0 )
1391
1381
iocb -> ki_pos = ret ;
1392
- out :
1393
1382
tun_put (tun );
1394
1383
return ret ;
1395
1384
}
@@ -1471,6 +1460,7 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
1471
1460
{
1472
1461
struct tun_file * tfile = container_of (sock , struct tun_file , socket );
1473
1462
struct tun_struct * tun = __tun_get (tfile );
1463
+ struct iov_iter to ;
1474
1464
int ret ;
1475
1465
1476
1466
if (!tun )
@@ -1485,8 +1475,8 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
1485
1475
SOL_PACKET , TUN_TX_TIMESTAMP );
1486
1476
goto out ;
1487
1477
}
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 );
1490
1480
if (ret > total_len ) {
1491
1481
m -> msg_flags |= MSG_TRUNC ;
1492
1482
ret = flags & MSG_TRUNC ? ret : total_len ;
@@ -2242,8 +2232,8 @@ static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
2242
2232
static const struct file_operations tun_fops = {
2243
2233
.owner = THIS_MODULE ,
2244
2234
.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 ,
2247
2237
.write = do_sync_write ,
2248
2238
.aio_write = tun_chr_aio_write ,
2249
2239
.poll = tun_chr_poll ,
0 commit comments