Skip to content

Commit 70ba85e

Browse files
Thomas-fouriergregkh
authored andcommitted
ksmbd: smbd: fix dma_unmap_sg() nents
[ Upstream commit 98e3e2b ] The dma_unmap_sg() functions should be called with the same nents as the dma_map_sg(), not the value the map function returned. Fixes: 0626e66 ("cifsd: add server handler for central processing and tranport layers") Cc: <stable@vger.kernel.org> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> [ Context ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c08cf31 commit 70ba85e

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

fs/smb/server/transport_rdma.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,14 +1108,12 @@ static int get_sg_list(void *buf, int size, struct scatterlist *sg_list, int nen
11081108

11091109
static int get_mapped_sg_list(struct ib_device *device, void *buf, int size,
11101110
struct scatterlist *sg_list, int nentries,
1111-
enum dma_data_direction dir)
1111+
enum dma_data_direction dir, int *npages)
11121112
{
1113-
int npages;
1114-
1115-
npages = get_sg_list(buf, size, sg_list, nentries);
1116-
if (npages < 0)
1113+
*npages = get_sg_list(buf, size, sg_list, nentries);
1114+
if (*npages < 0)
11171115
return -EINVAL;
1118-
return ib_dma_map_sg(device, sg_list, npages, dir);
1116+
return ib_dma_map_sg(device, sg_list, *npages, dir);
11191117
}
11201118

11211119
static int post_sendmsg(struct smb_direct_transport *t,
@@ -1184,20 +1182,21 @@ static int smb_direct_post_send_data(struct smb_direct_transport *t,
11841182
for (i = 0; i < niov; i++) {
11851183
struct ib_sge *sge;
11861184
int sg_cnt;
1185+
int npages;
11871186

11881187
sg_init_table(sg, SMB_DIRECT_MAX_SEND_SGES - 1);
11891188
sg_cnt = get_mapped_sg_list(t->cm_id->device,
11901189
iov[i].iov_base, iov[i].iov_len,
11911190
sg, SMB_DIRECT_MAX_SEND_SGES - 1,
1192-
DMA_TO_DEVICE);
1191+
DMA_TO_DEVICE, &npages);
11931192
if (sg_cnt <= 0) {
11941193
pr_err("failed to map buffer\n");
11951194
ret = -ENOMEM;
11961195
goto err;
11971196
} else if (sg_cnt + msg->num_sge > SMB_DIRECT_MAX_SEND_SGES) {
11981197
pr_err("buffer not fitted into sges\n");
11991198
ret = -E2BIG;
1200-
ib_dma_unmap_sg(t->cm_id->device, sg, sg_cnt,
1199+
ib_dma_unmap_sg(t->cm_id->device, sg, npages,
12011200
DMA_TO_DEVICE);
12021201
goto err;
12031202
}

0 commit comments

Comments
 (0)