Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3158f36 authored by Asias He's avatar Asias He Committed by Nicholas Bellinger
Browse files

tcm_vhost: Use iov_num_pages to calculate sgl_count

parent 765b34fd
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -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
	 * Find out how long sglist needs to be
	 */
	 */
	sgl_count = 0;
	sgl_count = 0;
	for (i = 0; i < niov; i++) {
	for (i = 0; i < niov; i++)
		sgl_count += (((uintptr_t)iov[i].iov_base + iov[i].iov_len +
		sgl_count += iov_num_pages(&iov[i]);
				PAGE_SIZE - 1) >> PAGE_SHIFT) -

				((uintptr_t)iov[i].iov_base >> PAGE_SHIFT);
	}
	/* TODO overflow checking */
	/* TODO overflow checking */


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