lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 26 Sep 2021 14:11:23 +0800
From:   Cai Huoqing <caihuoqing@...du.com>
To:     <caihuoqing@...du.com>
CC:     Mustafa Ismail <mustafa.ismail@...el.com>,
        Shiraz Saleem <shiraz.saleem@...el.com>,
        Doug Ledford <dledford@...hat.com>,
        "Jason Gunthorpe" <jgg@...pe.ca>, <linux-rdma@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH] RDMA/irdma: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()

Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
with dma_alloc_coherent/dma_free_coherent() helps to reduce
code size, and simplify the code, and coherent DMA will not
clear the cache every time.

Signed-off-by: Cai Huoqing <caihuoqing@...du.com>
---
 drivers/infiniband/hw/irdma/puda.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/puda.c b/drivers/infiniband/hw/irdma/puda.c
index 58e7d875643b..feafe21b12c6 100644
--- a/drivers/infiniband/hw/irdma/puda.c
+++ b/drivers/infiniband/hw/irdma/puda.c
@@ -151,24 +151,15 @@ static struct irdma_puda_buf *irdma_puda_alloc_buf(struct irdma_sc_dev *dev,
 
 	buf = buf_mem.va;
 	buf->mem.size = len;
-	buf->mem.va = kzalloc(buf->mem.size, GFP_KERNEL);
+	buf->mem.va = dma_alloc_coherent(dev->hw->device, len,
+					 &buf->mem.pa, GFP_KERNEL);
 	if (!buf->mem.va)
-		goto free_virt;
-	buf->mem.pa = dma_map_single(dev->hw->device, buf->mem.va,
-				     buf->mem.size, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dev->hw->device, buf->mem.pa)) {
-		kfree(buf->mem.va);
-		goto free_virt;
-	}
+		return NULL;
 
 	buf->buf_mem.va = buf_mem.va;
 	buf->buf_mem.size = buf_mem.size;
 
 	return buf;
-
-free_virt:
-	kfree(buf_mem.va);
-	return NULL;
 }
 
 /**
@@ -179,9 +170,7 @@ static struct irdma_puda_buf *irdma_puda_alloc_buf(struct irdma_sc_dev *dev,
 static void irdma_puda_dele_buf(struct irdma_sc_dev *dev,
 				struct irdma_puda_buf *buf)
 {
-	dma_unmap_single(dev->hw->device, buf->mem.pa, buf->mem.size,
-			 DMA_BIDIRECTIONAL);
-	kfree(buf->mem.va);
+	dma_free_coherent(dev->hw->device, buf->mem.size, buf->mem.va, buf->mem.pa);
 	kfree(buf->buf_mem.va);
 }
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ