Skip to content

Commit

Permalink
CIFS: Calculate the correct request length based on page offset and t…
Browse files Browse the repository at this point in the history
…ail size

It's possible that the page offset is non-zero in the pages in a request,
change the function to calculate the correct data buffer length.

Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Long Li authored and Steve French committed Jun 5, 2018
1 parent ee25c6d commit c06a0f2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions fs/cifs/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,24 @@ rqst_len(struct smb_rqst *rqst)
for (i = 0; i < rqst->rq_nvec; i++)
buflen += iov[i].iov_len;

/* add in the page array if there is one */
/*
* Add in the page array if there is one. The caller needs to make
* sure rq_offset and rq_tailsz are set correctly. If a buffer of
* multiple pages ends at page boundary, rq_tailsz needs to be set to
* PAGE_SIZE.
*/
if (rqst->rq_npages) {
buflen += rqst->rq_pagesz * (rqst->rq_npages - 1);
buflen += rqst->rq_tailsz;
if (rqst->rq_npages == 1)
buflen += rqst->rq_tailsz;
else {
/*
* If there is more than one page, calculate the
* buffer length based on rq_offset and rq_tailsz
*/
buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) -
rqst->rq_offset;
buflen += rqst->rq_tailsz;
}
}

return buflen;
Expand Down

0 comments on commit c06a0f2

Please sign in to comment.