]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb: client: make sure we call ib_dma_unmap_single() only if we called ib_dma_map_sin...
authorStefan Metzmacher <metze@samba.org>
Mon, 4 Aug 2025 12:10:14 +0000 (14:10 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 14:39:29 +0000 (16:39 +0200)
[ Upstream commit 047682c370b6f18fec818b57b0ed8b501bdb79f8 ]

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: f198186aa9bb ("CIFS: SMBD: Establish SMB Direct connection")
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/smbdirect.c

index 80b101aee48d1f84e8abbe1b147f37a72587c55b..fdc94f46b935d6afa904381d6b0431c940ebaa2b 100644 (file)
@@ -1055,6 +1055,7 @@ static int smbd_post_recv(
        if (rc) {
                ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
                                    response->sge.length, DMA_FROM_DEVICE);
+               response->sge.length = 0;
                smbd_disconnect_rdma_connection(info);
                log_rdma_recv(ERR, "ib_post_recv failed rc=%d\n", rc);
        }
@@ -1184,8 +1185,13 @@ static void put_receive_buffer(
        struct smbdirect_socket *sc = &info->socket;
        unsigned long flags;
 
-       ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
-               response->sge.length, DMA_FROM_DEVICE);
+       if (likely(response->sge.length != 0)) {
+               ib_dma_unmap_single(sc->ib.dev,
+                                   response->sge.addr,
+                                   response->sge.length,
+                                   DMA_FROM_DEVICE);
+               response->sge.length = 0;
+       }
 
        spin_lock_irqsave(&info->receive_queue_lock, flags);
        list_add_tail(&response->list, &info->receive_queue);
@@ -1219,6 +1225,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
                        goto allocate_failed;
 
                response->info = info;
+               response->sge.length = 0;
                list_add_tail(&response->list, &info->receive_queue);
                info->count_receive_queue++;
        }