aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDmitriy Monakhov <dmonakhov@openvz.org>2007-05-08 03:23:02 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:14:57 -0400
commit0ceb331433e8aad9c5f441a965d7c681f8b9046f (patch)
treefd3d679a4015242dd65f0721f52242ad47619910 /fs
parentb46b8f19c9cd435ecac4d9d12b39d78c137ecd66 (diff)
mm: move common segment checks to separate helper function
[akpm@linux-foundation.org: cleanup] Signed-off-by: Monakhov Dmitriy <dmonakhov@openvz.org> Cc: Christoph Hellwig <hch@lst.de> Acked-by: Anton Altaparmakov <aia21@cam.ac.uk> Acked-by: David Chinner <dgc@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ntfs/file.c21
-rw-r--r--fs/xfs/linux-2.6/xfs_lrw.c22
2 files changed, 6 insertions, 37 deletions
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index dbbac5593106..621de369e6f8 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -2129,28 +2129,13 @@ static ssize_t ntfs_file_aio_write_nolock(struct kiocb *iocb,
2129 struct address_space *mapping = file->f_mapping; 2129 struct address_space *mapping = file->f_mapping;
2130 struct inode *inode = mapping->host; 2130 struct inode *inode = mapping->host;
2131 loff_t pos; 2131 loff_t pos;
2132 unsigned long seg;
2133 size_t count; /* after file limit checks */ 2132 size_t count; /* after file limit checks */
2134 ssize_t written, err; 2133 ssize_t written, err;
2135 2134
2136 count = 0; 2135 count = 0;
2137 for (seg = 0; seg < nr_segs; seg++) { 2136 err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ);
2138 const struct iovec *iv = &iov[seg]; 2137 if (err)
2139 /* 2138 return err;
2140 * If any segment has a negative length, or the cumulative
2141 * length ever wraps negative then return -EINVAL.
2142 */
2143 count += iv->iov_len;
2144 if (unlikely((ssize_t)(count|iv->iov_len) < 0))
2145 return -EINVAL;
2146 if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
2147 continue;
2148 if (!seg)
2149 return -EFAULT;
2150 nr_segs = seg;
2151 count -= iv->iov_len; /* This segment is no good */
2152 break;
2153 }
2154 pos = *ppos; 2139 pos = *ppos;
2155 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); 2140 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
2156 /* We can write back this queue in page reclaim. */ 2141 /* We can write back this queue in page reclaim. */
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c
index ff8d64eba9f8..558076dd0752 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.c
+++ b/fs/xfs/linux-2.6/xfs_lrw.c
@@ -639,7 +639,6 @@ xfs_write(
639 xfs_fsize_t isize, new_size; 639 xfs_fsize_t isize, new_size;
640 xfs_iocore_t *io; 640 xfs_iocore_t *io;
641 bhv_vnode_t *vp; 641 bhv_vnode_t *vp;
642 unsigned long seg;
643 int iolock; 642 int iolock;
644 int eventsent = 0; 643 int eventsent = 0;
645 bhv_vrwlock_t locktype; 644 bhv_vrwlock_t locktype;
@@ -652,24 +651,9 @@ xfs_write(
652 vp = BHV_TO_VNODE(bdp); 651 vp = BHV_TO_VNODE(bdp);
653 xip = XFS_BHVTOI(bdp); 652 xip = XFS_BHVTOI(bdp);
654 653
655 for (seg = 0; seg < segs; seg++) { 654 error = generic_segment_checks(iovp, &segs, &ocount, VERIFY_READ);
656 const struct iovec *iv = &iovp[seg]; 655 if (error)
657 656 return error;
658 /*
659 * If any segment has a negative length, or the cumulative
660 * length ever wraps negative then return -EINVAL.
661 */
662 ocount += iv->iov_len;
663 if (unlikely((ssize_t)(ocount|iv->iov_len) < 0))
664 return -EINVAL;
665 if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
666 continue;
667 if (seg == 0)
668 return -EFAULT;
669 segs = seg;
670 ocount -= iv->iov_len; /* This segment is no good */
671 break;
672 }
673 657
674 count = ocount; 658 count = ocount;
675 pos = *offset; 659 pos = *offset;