diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-03-04 15:24:06 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-05-06 17:32:43 -0400 |
commit | cb66a7a1f149ff705fa37cad6d1252b046e0ad4f (patch) | |
tree | 32dd17f294e9ef96bfea727bba313a33590917ab /mm | |
parent | 0ae5e4d370599592eab845527b31708a4f3411be (diff) |
kill generic_segment_checks()
all callers of ->aio_read() and ->aio_write() have iov/nr_segs already
checked - generic_segment_checks() done after that is just an odd way
to spell iov_length().
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/filemap.c | 53 | ||||
-rw-r--r-- | mm/shmem.c | 7 |
2 files changed, 5 insertions, 55 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index a840890ed39f..7c1417b0bd7b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c | |||
@@ -1663,45 +1663,6 @@ out: | |||
1663 | return written ? written : error; | 1663 | return written ? written : error; |
1664 | } | 1664 | } |
1665 | 1665 | ||
1666 | /* | ||
1667 | * Performs necessary checks before doing a write | ||
1668 | * @iov: io vector request | ||
1669 | * @nr_segs: number of segments in the iovec | ||
1670 | * @count: number of bytes to write | ||
1671 | * @access_flags: type of access: %VERIFY_READ or %VERIFY_WRITE | ||
1672 | * | ||
1673 | * Adjust number of segments and amount of bytes to write (nr_segs should be | ||
1674 | * properly initialized first). Returns appropriate error code that caller | ||
1675 | * should return or zero in case that write should be allowed. | ||
1676 | */ | ||
1677 | int generic_segment_checks(const struct iovec *iov, | ||
1678 | unsigned long *nr_segs, size_t *count, int access_flags) | ||
1679 | { | ||
1680 | unsigned long seg; | ||
1681 | size_t cnt = 0; | ||
1682 | for (seg = 0; seg < *nr_segs; seg++) { | ||
1683 | const struct iovec *iv = &iov[seg]; | ||
1684 | |||
1685 | /* | ||
1686 | * If any segment has a negative length, or the cumulative | ||
1687 | * length ever wraps negative then return -EINVAL. | ||
1688 | */ | ||
1689 | cnt += iv->iov_len; | ||
1690 | if (unlikely((ssize_t)(cnt|iv->iov_len) < 0)) | ||
1691 | return -EINVAL; | ||
1692 | if (access_ok(access_flags, iv->iov_base, iv->iov_len)) | ||
1693 | continue; | ||
1694 | if (seg == 0) | ||
1695 | return -EFAULT; | ||
1696 | *nr_segs = seg; | ||
1697 | cnt -= iv->iov_len; /* This segment is no good */ | ||
1698 | break; | ||
1699 | } | ||
1700 | *count = cnt; | ||
1701 | return 0; | ||
1702 | } | ||
1703 | EXPORT_SYMBOL(generic_segment_checks); | ||
1704 | |||
1705 | /** | 1666 | /** |
1706 | * generic_file_aio_read - generic filesystem read routine | 1667 | * generic_file_aio_read - generic filesystem read routine |
1707 | * @iocb: kernel I/O control block | 1668 | * @iocb: kernel I/O control block |
@@ -1717,15 +1678,12 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | |||
1717 | unsigned long nr_segs, loff_t pos) | 1678 | unsigned long nr_segs, loff_t pos) |
1718 | { | 1679 | { |
1719 | struct file *filp = iocb->ki_filp; | 1680 | struct file *filp = iocb->ki_filp; |
1720 | ssize_t retval; | 1681 | ssize_t retval = 0; |
1721 | size_t count; | 1682 | size_t count; |
1722 | loff_t *ppos = &iocb->ki_pos; | 1683 | loff_t *ppos = &iocb->ki_pos; |
1723 | struct iov_iter i; | 1684 | struct iov_iter i; |
1724 | 1685 | ||
1725 | count = 0; | 1686 | count = iov_length(iov, nr_segs); |
1726 | retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE); | ||
1727 | if (retval) | ||
1728 | return retval; | ||
1729 | iov_iter_init(&i, iov, nr_segs, count, 0); | 1687 | iov_iter_init(&i, iov, nr_segs, count, 0); |
1730 | 1688 | ||
1731 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ | 1689 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ |
@@ -2615,12 +2573,7 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2615 | ssize_t status; | 2573 | ssize_t status; |
2616 | struct iov_iter from; | 2574 | struct iov_iter from; |
2617 | 2575 | ||
2618 | ocount = 0; | 2576 | count = ocount = iov_length(iov, nr_segs); |
2619 | err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ); | ||
2620 | if (err) | ||
2621 | return err; | ||
2622 | |||
2623 | count = ocount; | ||
2624 | 2577 | ||
2625 | /* We can write back this queue in page reclaim */ | 2578 | /* We can write back this queue in page reclaim */ |
2626 | current->backing_dev_info = mapping->backing_dev_info; | 2579 | current->backing_dev_info = mapping->backing_dev_info; |
diff --git a/mm/shmem.c b/mm/shmem.c index 9f70e02111c6..2a93e625adaf 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -1412,14 +1412,11 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb, | |||
1412 | unsigned long offset; | 1412 | unsigned long offset; |
1413 | enum sgp_type sgp = SGP_READ; | 1413 | enum sgp_type sgp = SGP_READ; |
1414 | int error = 0; | 1414 | int error = 0; |
1415 | ssize_t retval; | 1415 | ssize_t retval = 0; |
1416 | size_t count; | 1416 | size_t count = iov_length(iov, nr_segs); |
1417 | loff_t *ppos = &iocb->ki_pos; | 1417 | loff_t *ppos = &iocb->ki_pos; |
1418 | struct iov_iter iter; | 1418 | struct iov_iter iter; |
1419 | 1419 | ||
1420 | retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE); | ||
1421 | if (retval) | ||
1422 | return retval; | ||
1423 | iov_iter_init(&iter, iov, nr_segs, count, 0); | 1420 | iov_iter_init(&iter, iov, nr_segs, count, 0); |
1424 | 1421 | ||
1425 | /* | 1422 | /* |