Skip to content

Commit d406d26

Browse files
Paulo Alcantarasmfrench
authored andcommitted
cifs: skip alloc when request has no pages
When smb3_init_transform_rq() was being called with requests (@old_rq) which had no pages, it was unnecessarily allocating a single page for every request in @new_rq. Fix this by skipping page array allocation when requests have no pages (e.g. !smb_rqst::rq_npages). Also get rid of deprecated kmap() and use kmap_local_page() instead while we're at it. Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ebaad77 commit d406d26

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

fs/cifs/smb2ops.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4445,21 +4445,27 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
44454445
int rc = -ENOMEM;
44464446

44474447
for (i = 1; i < num_rqst; i++) {
4448-
npages = old_rq[i - 1].rq_npages;
4448+
struct smb_rqst *old = &old_rq[i - 1];
4449+
struct smb_rqst *new = &new_rq[i];
4450+
4451+
orig_len += smb_rqst_len(server, old);
4452+
new->rq_iov = old->rq_iov;
4453+
new->rq_nvec = old->rq_nvec;
4454+
4455+
npages = old->rq_npages;
4456+
if (!npages)
4457+
continue;
4458+
44494459
pages = kmalloc_array(npages, sizeof(struct page *),
44504460
GFP_KERNEL);
44514461
if (!pages)
44524462
goto err_free;
44534463

4454-
new_rq[i].rq_pages = pages;
4455-
new_rq[i].rq_npages = npages;
4456-
new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4457-
new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4458-
new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4459-
new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4460-
new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4461-
4462-
orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4464+
new->rq_pages = pages;
4465+
new->rq_npages = npages;
4466+
new->rq_offset = old->rq_offset;
4467+
new->rq_pagesz = old->rq_pagesz;
4468+
new->rq_tailsz = old->rq_tailsz;
44634469

44644470
for (j = 0; j < npages; j++) {
44654471
pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
@@ -4472,14 +4478,14 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
44724478
char *dst, *src;
44734479
unsigned int offset, len;
44744480

4475-
rqst_page_get_length(&new_rq[i], j, &len, &offset);
4481+
rqst_page_get_length(new, j, &len, &offset);
44764482

4477-
dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4478-
src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4483+
dst = kmap_local_page(new->rq_pages[j]) + offset;
4484+
src = kmap_local_page(old->rq_pages[j]) + offset;
44794485

44804486
memcpy(dst, src, len);
4481-
kunmap(new_rq[i].rq_pages[j]);
4482-
kunmap(old_rq[i - 1].rq_pages[j]);
4487+
kunmap(new->rq_pages[j]);
4488+
kunmap(old->rq_pages[j]);
44834489
}
44844490
}
44854491

0 commit comments

Comments
 (0)