Skip to content

Commit

Permalink
tcm_vhost: Use iov_num_pages to calculate sgl_count
Browse files Browse the repository at this point in the history
Signed-off-by: Asias He <asias@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Asias He authored and Nicholas Bellinger committed Feb 13, 2013
1 parent 765b34f commit f3158f3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/vhost/tcm_vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,9 @@ static int vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *tv_cmd,
* Find out how long sglist needs to be
*/
sgl_count = 0;
for (i = 0; i < niov; i++) {
sgl_count += (((uintptr_t)iov[i].iov_base + iov[i].iov_len +
PAGE_SIZE - 1) >> PAGE_SHIFT) -
((uintptr_t)iov[i].iov_base >> PAGE_SHIFT);
}
for (i = 0; i < niov; i++)
sgl_count += iov_num_pages(&iov[i]);

/* TODO overflow checking */

sg = kmalloc(sizeof(tv_cmd->tvc_sgl[0]) * sgl_count, GFP_ATOMIC);
Expand Down

0 comments on commit f3158f3

Please sign in to comment.