Commit 6e8087a4 authored by K. Y. Srinivasan's avatar K. Y. Srinivasan Committed by Greg Kroah-Hartman

Staging: hv: storvsc: Fix a bug in create_bounce_buffer()

Set the length field of the scatter gather elements correctly when we create
the bounce buffer. When we use the bounce buffer for a "write" operation,
the act of copying to the bounce buffer, correctly deals with this issue.
However, on the "read" side, the current code was not correctly setting
the buffer length. Fix this bug. Note that when we copy from the bounce
buffer (for the read case), the amount we copy is controlled by the original
scatter gather list given to the driver.
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Reported-by: default avatarDadok Milan <dadok@kvados.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 4219001f
...@@ -893,12 +893,14 @@ static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) ...@@ -893,12 +893,14 @@ static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl,
unsigned int sg_count, unsigned int sg_count,
unsigned int len) unsigned int len,
int write)
{ {
int i; int i;
int num_pages; int num_pages;
struct scatterlist *bounce_sgl; struct scatterlist *bounce_sgl;
struct page *page_buf; struct page *page_buf;
unsigned int buf_len = ((write == WRITE_TYPE) ? 0 : PAGE_SIZE);
num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT; num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT;
...@@ -910,7 +912,7 @@ static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, ...@@ -910,7 +912,7 @@ static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl,
page_buf = alloc_page(GFP_ATOMIC); page_buf = alloc_page(GFP_ATOMIC);
if (!page_buf) if (!page_buf)
goto cleanup; goto cleanup;
sg_set_page(&bounce_sgl[i], page_buf, 0, 0); sg_set_page(&bounce_sgl[i], page_buf, buf_len, 0);
} }
return bounce_sgl; return bounce_sgl;
...@@ -1348,7 +1350,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) ...@@ -1348,7 +1350,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) { if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) {
cmd_request->bounce_sgl = cmd_request->bounce_sgl =
create_bounce_buffer(sgl, scsi_sg_count(scmnd), create_bounce_buffer(sgl, scsi_sg_count(scmnd),
scsi_bufflen(scmnd)); scsi_bufflen(scmnd),
vm_srb->data_in);
if (!cmd_request->bounce_sgl) { if (!cmd_request->bounce_sgl) {
scmnd->host_scribble = NULL; scmnd->host_scribble = NULL;
mempool_free(cmd_request, mempool_free(cmd_request,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment