mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
mm: move common segment checks to separate helper function
[[email protected]: cleanup] Signed-off-by: Monakhov Dmitriy <[email protected]> Cc: Christoph Hellwig <[email protected]> Acked-by: Anton Altaparmakov <[email protected]> Acked-by: David Chinner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
b46b8f19c9
commit
0ceb331433
4 changed files with 53 additions and 74 deletions
82
mm/filemap.c
82
mm/filemap.c
|
|
@ -1110,6 +1110,45 @@ success:
|
|||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Performs necessary checks before doing a write
|
||||
* @iov: io vector request
|
||||
* @nr_segs: number of segments in the iovec
|
||||
* @count: number of bytes to write
|
||||
* @access_flags: type of access: %VERIFY_READ or %VERIFY_WRITE
|
||||
*
|
||||
* Adjust number of segments and amount of bytes to write (nr_segs should be
|
||||
* properly initialized first). Returns appropriate error code that caller
|
||||
* should return or zero in case that write should be allowed.
|
||||
*/
|
||||
int generic_segment_checks(const struct iovec *iov,
|
||||
unsigned long *nr_segs, size_t *count, int access_flags)
|
||||
{
|
||||
unsigned long seg;
|
||||
size_t cnt = 0;
|
||||
for (seg = 0; seg < *nr_segs; seg++) {
|
||||
const struct iovec *iv = &iov[seg];
|
||||
|
||||
/*
|
||||
* If any segment has a negative length, or the cumulative
|
||||
* length ever wraps negative then return -EINVAL.
|
||||
*/
|
||||
cnt += iv->iov_len;
|
||||
if (unlikely((ssize_t)(cnt|iv->iov_len) < 0))
|
||||
return -EINVAL;
|
||||
if (access_ok(access_flags, iv->iov_base, iv->iov_len))
|
||||
continue;
|
||||
if (seg == 0)
|
||||
return -EFAULT;
|
||||
*nr_segs = seg;
|
||||
cnt -= iv->iov_len; /* This segment is no good */
|
||||
break;
|
||||
}
|
||||
*count = cnt;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(generic_segment_checks);
|
||||
|
||||
/**
|
||||
* generic_file_aio_read - generic filesystem read routine
|
||||
* @iocb: kernel I/O control block
|
||||
|
|
@ -1131,24 +1170,9 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
|
|||
loff_t *ppos = &iocb->ki_pos;
|
||||
|
||||
count = 0;
|
||||
for (seg = 0; seg < nr_segs; seg++) {
|
||||
const struct iovec *iv = &iov[seg];
|
||||
|
||||
/*
|
||||
* If any segment has a negative length, or the cumulative
|
||||
* length ever wraps negative then return -EINVAL.
|
||||
*/
|
||||
count += iv->iov_len;
|
||||
if (unlikely((ssize_t)(count|iv->iov_len) < 0))
|
||||
return -EINVAL;
|
||||
if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len))
|
||||
continue;
|
||||
if (seg == 0)
|
||||
return -EFAULT;
|
||||
nr_segs = seg;
|
||||
count -= iv->iov_len; /* This segment is no good */
|
||||
break;
|
||||
}
|
||||
retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
/* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
|
||||
if (filp->f_flags & O_DIRECT) {
|
||||
|
|
@ -2218,30 +2242,14 @@ __generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
|
|||
size_t ocount; /* original count */
|
||||
size_t count; /* after file limit checks */
|
||||
struct inode *inode = mapping->host;
|
||||
unsigned long seg;
|
||||
loff_t pos;
|
||||
ssize_t written;
|
||||
ssize_t err;
|
||||
|
||||
ocount = 0;
|
||||
for (seg = 0; seg < nr_segs; seg++) {
|
||||
const struct iovec *iv = &iov[seg];
|
||||
|
||||
/*
|
||||
* If any segment has a negative length, or the cumulative
|
||||
* length ever wraps negative then return -EINVAL.
|
||||
*/
|
||||
ocount += iv->iov_len;
|
||||
if (unlikely((ssize_t)(ocount|iv->iov_len) < 0))
|
||||
return -EINVAL;
|
||||
if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
|
||||
continue;
|
||||
if (seg == 0)
|
||||
return -EFAULT;
|
||||
nr_segs = seg;
|
||||
ocount -= iv->iov_len; /* This segment is no good */
|
||||
break;
|
||||
}
|
||||
err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
count = ocount;
|
||||
pos = *ppos;
|
||||
|
|
|
|||
Loading…
Reference in a new issue