Skip to content

Commit 047682c

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: make sure we call ib_dma_unmap_single() only if we called ib_dma_map_single already
In case of failures either ib_dma_map_single() might not be called yet or ib_dma_unmap_single() was already called. We should make sure put_receive_buffer() only calls ib_dma_unmap_single() if needed. Cc: Steve French <smfrench@gmail.com> Cc: Tom Talpey <tom@talpey.com> Cc: Long Li <longli@microsoft.com> Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Fixes: f198186 ("CIFS: SMBD: Establish SMB Direct connection") Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 24b6afc commit 047682c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

fs/smb/client/smbdirect.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ static int smbd_post_recv(
10571057
if (rc) {
10581058
ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
10591059
response->sge.length, DMA_FROM_DEVICE);
1060+
response->sge.length = 0;
10601061
smbd_disconnect_rdma_connection(info);
10611062
log_rdma_recv(ERR, "ib_post_recv failed rc=%d\n", rc);
10621063
}
@@ -1186,8 +1187,13 @@ static void put_receive_buffer(
11861187
struct smbdirect_socket *sc = &info->socket;
11871188
unsigned long flags;
11881189

1189-
ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
1190-
response->sge.length, DMA_FROM_DEVICE);
1190+
if (likely(response->sge.length != 0)) {
1191+
ib_dma_unmap_single(sc->ib.dev,
1192+
response->sge.addr,
1193+
response->sge.length,
1194+
DMA_FROM_DEVICE);
1195+
response->sge.length = 0;
1196+
}
11911197

11921198
spin_lock_irqsave(&info->receive_queue_lock, flags);
11931199
list_add_tail(&response->list, &info->receive_queue);
@@ -1221,6 +1227,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12211227
goto allocate_failed;
12221228

12231229
response->info = info;
1230+
response->sge.length = 0;
12241231
list_add_tail(&response->list, &info->receive_queue);
12251232
info->count_receive_queue++;
12261233
}

0 commit comments

Comments
 (0)