mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 06:40:54 +07:00
block: Use rw_copy_check_uvector()
No need for silly open coding - and struct sg_iovec has exactly the same layout as struct iovec... Signed-off-by: Kent Overstreet <kmo@daterainc.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
23779fbc99
commit
e0ce0eacb3
@ -286,7 +286,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
|
|||||||
struct sg_io_hdr *hdr, fmode_t mode)
|
struct sg_io_hdr *hdr, fmode_t mode)
|
||||||
{
|
{
|
||||||
unsigned long start_time;
|
unsigned long start_time;
|
||||||
int writing = 0, ret = 0;
|
ssize_t ret = 0;
|
||||||
|
int writing = 0;
|
||||||
struct request *rq;
|
struct request *rq;
|
||||||
char sense[SCSI_SENSE_BUFFERSIZE];
|
char sense[SCSI_SENSE_BUFFERSIZE];
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
@ -321,37 +322,16 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hdr->iovec_count) {
|
if (hdr->iovec_count) {
|
||||||
const int size = sizeof(struct sg_iovec) * hdr->iovec_count;
|
|
||||||
size_t iov_data_len;
|
size_t iov_data_len;
|
||||||
struct sg_iovec *sg_iov;
|
|
||||||
struct iovec *iov;
|
struct iovec *iov;
|
||||||
int i;
|
|
||||||
|
|
||||||
sg_iov = kmalloc(size, GFP_KERNEL);
|
ret = rw_copy_check_uvector(-1, hdr->dxferp, hdr->iovec_count,
|
||||||
if (!sg_iov) {
|
0, NULL, &iov);
|
||||||
ret = -ENOMEM;
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
if (copy_from_user(sg_iov, hdr->dxferp, size)) {
|
iov_data_len = ret;
|
||||||
kfree(sg_iov);
|
ret = 0;
|
||||||
ret = -EFAULT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sum up the vecs, making sure they don't overflow
|
|
||||||
*/
|
|
||||||
iov = (struct iovec *) sg_iov;
|
|
||||||
iov_data_len = 0;
|
|
||||||
for (i = 0; i < hdr->iovec_count; i++) {
|
|
||||||
if (iov_data_len + iov[i].iov_len < iov_data_len) {
|
|
||||||
kfree(sg_iov);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
iov_data_len += iov[i].iov_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SG_IO howto says that the shorter of the two wins */
|
/* SG_IO howto says that the shorter of the two wins */
|
||||||
if (hdr->dxfer_len < iov_data_len) {
|
if (hdr->dxfer_len < iov_data_len) {
|
||||||
@ -361,9 +341,10 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
|
|||||||
iov_data_len = hdr->dxfer_len;
|
iov_data_len = hdr->dxfer_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blk_rq_map_user_iov(q, rq, NULL, sg_iov, hdr->iovec_count,
|
ret = blk_rq_map_user_iov(q, rq, NULL, (struct sg_iovec *) iov,
|
||||||
|
hdr->iovec_count,
|
||||||
iov_data_len, GFP_KERNEL);
|
iov_data_len, GFP_KERNEL);
|
||||||
kfree(sg_iov);
|
kfree(iov);
|
||||||
} else if (hdr->dxfer_len)
|
} else if (hdr->dxfer_len)
|
||||||
ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len,
|
ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
Loading…
Reference in New Issue
Block a user