Skip to content

Commit e1469f5

Browse files
dhowellssmfrench
authored andcommitted
cifs: Use netfs_alloc/free_folioq_buffer()
Use netfs_alloc/free_folioq_buffer() rather than doing its own version. Signed-off-by: David Howells <dhowells@redhat.com> cc: Steve French <sfrench@samba.org> cc: Paulo Alcantara <pc@manguebit.org> cc: Shyam Prasad N <sprasad@microsoft.com> cc: Tom Talpey <tom@talpey.com> (RDMA, smbdirect) cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent f78b83d commit e1469f5

1 file changed

Lines changed: 10 additions & 63 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,61 +4484,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
44844484
return rc;
44854485
}
44864486

4487-
/*
4488-
* Clear a read buffer, discarding the folios which have the 1st mark set.
4489-
*/
4490-
static void cifs_clear_folioq_buffer(struct folio_queue *buffer)
4491-
{
4492-
struct folio_queue *folioq;
4493-
4494-
while ((folioq = buffer)) {
4495-
for (int s = 0; s < folioq_count(folioq); s++)
4496-
if (folioq_is_marked(folioq, s))
4497-
folio_put(folioq_folio(folioq, s));
4498-
buffer = folioq->next;
4499-
kfree(folioq);
4500-
}
4501-
}
4502-
4503-
/*
4504-
* Allocate buffer space into a folio queue.
4505-
*/
4506-
static struct folio_queue *cifs_alloc_folioq_buffer(ssize_t size)
4507-
{
4508-
struct folio_queue *buffer = NULL, *tail = NULL, *p;
4509-
struct folio *folio;
4510-
unsigned int slot;
4511-
4512-
do {
4513-
if (!tail || folioq_full(tail)) {
4514-
p = kmalloc(sizeof(*p), GFP_NOFS);
4515-
if (!p)
4516-
goto nomem;
4517-
folioq_init(p, 0);
4518-
if (tail) {
4519-
tail->next = p;
4520-
p->prev = tail;
4521-
} else {
4522-
buffer = p;
4523-
}
4524-
tail = p;
4525-
}
4526-
4527-
folio = folio_alloc(GFP_KERNEL|__GFP_HIGHMEM, 0);
4528-
if (!folio)
4529-
goto nomem;
4530-
4531-
slot = folioq_append_mark(tail, folio);
4532-
size -= folioq_folio_size(tail, slot);
4533-
} while (size > 0);
4534-
4535-
return buffer;
4536-
4537-
nomem:
4538-
cifs_clear_folioq_buffer(buffer);
4539-
return NULL;
4540-
}
4541-
45424487
/*
45434488
* Copy data from an iterator to the folios in a folio queue buffer.
45444489
*/
@@ -4564,7 +4509,7 @@ void
45644509
smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
45654510
{
45664511
for (int i = 0; i < num_rqst; i++)
4567-
cifs_clear_folioq_buffer(rqst[i].rq_buffer);
4512+
netfs_free_folioq_buffer(rqst[i].rq_buffer);
45684513
}
45694514

45704515
/*
@@ -4599,8 +4544,10 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
45994544
new->rq_nvec = old->rq_nvec;
46004545

46014546
if (size > 0) {
4602-
buffer = cifs_alloc_folioq_buffer(size);
4603-
if (!buffer)
4547+
size_t cur_size = 0;
4548+
rc = netfs_alloc_folioq_buffer(NULL, &buffer, &cur_size,
4549+
size, GFP_NOFS);
4550+
if (rc < 0)
46044551
goto err_free;
46054552

46064553
new->rq_buffer = buffer;
@@ -4932,7 +4879,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
49324879
}
49334880

49344881
free_pages:
4935-
cifs_clear_folioq_buffer(dw->buffer);
4882+
netfs_free_folioq_buffer(dw->buffer);
49364883
cifs_small_buf_release(dw->buf);
49374884
kfree(dw);
49384885
}
@@ -4970,9 +4917,9 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
49704917
dw->len = len;
49714918
len = round_up(dw->len, PAGE_SIZE);
49724919

4973-
rc = -ENOMEM;
4974-
dw->buffer = cifs_alloc_folioq_buffer(len);
4975-
if (!dw->buffer)
4920+
size_t cur_size = 0;
4921+
rc = netfs_alloc_folioq_buffer(NULL, &dw->buffer, &cur_size, len, GFP_NOFS);
4922+
if (rc < 0)
49764923
goto discard_data;
49774924

49784925
iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
@@ -5033,7 +4980,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
50334980
}
50344981

50354982
free_pages:
5036-
cifs_clear_folioq_buffer(dw->buffer);
4983+
netfs_free_folioq_buffer(dw->buffer);
50374984
free_dw:
50384985
kfree(dw);
50394986
return rc;

0 commit comments

Comments
 (0)