From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de,
cl@linux.com, 42.hyeyoo@gmail.com, penberg@kernel.org,
rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz,
David.Laight@ACULAB.COM, david@redhat.com,
herbert@gondor.apana.org.au, davem@davemloft.net,
linux-crypto@vger.kernel.org, steffen.klassert@secunet.com,
netdev@vger.kernel.org, hca@linux.ibm.com, gor@linux.ibm.com,
agordeev@linux.ibm.com, borntraeger@linux.ibm.com,
svens@linux.ibm.com, linux-s390@vger.kernel.org,
michael@walle.cc, linux-i2c@vger.kernel.org, wsa@kernel.org
Subject: [PATCH 19/22] ethernet: rocker: Use dma_alloc_noncoherent() for dma buffer
Date: Sat, 19 Feb 2022 08:52:18 +0800 [thread overview]
Message-ID: <20220219005221.634-20-bhe@redhat.com> (raw)
In-Reply-To: <20220219005221.634-1-bhe@redhat.com>
Use dma_alloc_noncoherent() instead to get the DMA buffer.
[ 42.hyeyoo@gmail.com: Use dma_alloc_noncoherent() instead of
__get_free_pages.
Fix memory leak. ]
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: davem@davemloft.net
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
---
drivers/net/ethernet/rocker/rocker_main.c | 59 +++++++++--------------
1 file changed, 23 insertions(+), 36 deletions(-)
diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 3fcea211716c..b23dd9b70d8d 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -193,20 +193,17 @@ static int rocker_dma_test_offset(const struct rocker *rocker,
int i;
int err;
- alloc = kzalloc(ROCKER_TEST_DMA_BUF_SIZE * 2 + offset,
- GFP_KERNEL | GFP_DMA);
+ alloc = dma_alloc_noncoherent(&pdev->dev,
+ ROCKER_TEST_DMA_BUF_SIZE * 2 + offset,
+ &dma_handle,
+ DMA_BIDIRECTIONAL,
+ GFP_KERNEL);
if (!alloc)
return -ENOMEM;
+
buf = alloc + offset;
expect = buf + ROCKER_TEST_DMA_BUF_SIZE;
- dma_handle = dma_map_single(&pdev->dev, buf, ROCKER_TEST_DMA_BUF_SIZE,
- DMA_BIDIRECTIONAL);
- if (dma_mapping_error(&pdev->dev, dma_handle)) {
- err = -EIO;
- goto free_alloc;
- }
-
rocker_write64(rocker, TEST_DMA_ADDR, dma_handle);
rocker_write32(rocker, TEST_DMA_SIZE, ROCKER_TEST_DMA_BUF_SIZE);
@@ -215,14 +212,14 @@ static int rocker_dma_test_offset(const struct rocker *rocker,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
- goto unmap;
+ goto free;
memset(expect, 0, ROCKER_TEST_DMA_BUF_SIZE);
err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_CLEAR,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
- goto unmap;
+ goto free;
prandom_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
for (i = 0; i < ROCKER_TEST_DMA_BUF_SIZE; i++)
@@ -231,14 +228,11 @@ static int rocker_dma_test_offset(const struct rocker *rocker,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
- goto unmap;
-
-unmap:
- dma_unmap_single(&pdev->dev, dma_handle, ROCKER_TEST_DMA_BUF_SIZE,
- DMA_BIDIRECTIONAL);
-free_alloc:
- kfree(alloc);
+ goto free;
+free:
+ dma_free_noncoherent(&pdev->dev, ROCKER_TEST_DMA_BUF_SIZE * 2 + offset,
+ alloc, dma_handle, DMA_BIDIRECTIONAL);
return err;
}
@@ -500,20 +494,13 @@ static int rocker_dma_ring_bufs_alloc(const struct rocker *rocker,
dma_addr_t dma_handle;
char *buf;
- buf = kzalloc(buf_size, GFP_KERNEL | GFP_DMA);
+ buf = dma_alloc_noncoherent(&pdev->dev, buf_size,
+ &dma_handle, direction, GFP_KERNEL);
if (!buf) {
err = -ENOMEM;
goto rollback;
}
- dma_handle = dma_map_single(&pdev->dev, buf, buf_size,
- direction);
- if (dma_mapping_error(&pdev->dev, dma_handle)) {
- kfree(buf);
- err = -EIO;
- goto rollback;
- }
-
desc_info->data = buf;
desc_info->data_size = buf_size;
dma_unmap_addr_set(desc_info, mapaddr, dma_handle);
@@ -526,11 +513,10 @@ static int rocker_dma_ring_bufs_alloc(const struct rocker *rocker,
rollback:
for (i--; i >= 0; i--) {
const struct rocker_desc_info *desc_info = &info->desc_info[i];
-
- dma_unmap_single(&pdev->dev,
- dma_unmap_addr(desc_info, mapaddr),
- desc_info->data_size, direction);
- kfree(desc_info->data);
+ dma_free_noncoherent(&pdev->dev, desc_info->data_size,
+ desc_info->data,
+ dma_unmap_addr(desc_info, mapaddr),
+ direction);
}
return err;
}
@@ -548,10 +534,11 @@ static void rocker_dma_ring_bufs_free(const struct rocker *rocker,
desc->buf_addr = 0;
desc->buf_size = 0;
- dma_unmap_single(&pdev->dev,
- dma_unmap_addr(desc_info, mapaddr),
- desc_info->data_size, direction);
- kfree(desc_info->data);
+ dma_free_noncoherent(&pdev->dev,
+ desc_info->data_size,
+ desc_info->data,
+ dma_unmap_addr(desc_info, mapaddr),
+ direction);
}
}
--
2.17.2
next prev parent reply other threads:[~2022-02-19 0:58 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-19 0:51 [PATCH 00/22] Don't use kmalloc() with GFP_DMA Baoquan He
2022-02-19 0:52 ` [PATCH 01/22] parisc: pci-dma: remove stale code and comment Baoquan He
2022-02-19 7:07 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 02/22] net: moxa: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2022-02-19 7:07 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 03/22] gpu: ipu-v3: " Baoquan He
2022-02-19 7:07 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 04/22] drm/sti: Don't use GFP_DMA when calling dma_alloc_wc() Baoquan He
2022-02-19 7:08 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 05/22] sound: n64: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2022-02-19 7:08 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 06/22] fbdev: da8xx: " Baoquan He
2022-02-19 7:08 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 07/22] fbdev: mx3fb: Don't use GFP_DMA when calling dma_alloc_wc() Baoquan He
2022-02-19 7:08 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 08/22] usb: gadget: lpc32xx_udc: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2022-02-19 7:09 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 09/22] usb: cdns3: " Baoquan He
2022-02-19 7:09 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 10/22] uio: pruss: " Baoquan He
2022-02-19 7:09 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 11/22] staging: emxx_udc: " Baoquan He
2022-02-19 6:51 ` Wolfram Sang
2022-02-20 1:55 ` Baoquan He
2022-02-19 7:09 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 12/22] " Baoquan He
2022-02-19 7:10 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 13/22] spi: atmel: " Baoquan He
2022-02-19 7:10 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 14/22] spi: spi-ti-qspi: " Baoquan He
2022-02-19 7:12 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 15/22] usb: cdns3: Don't use GFP_DMA32 when calling dma_pool_alloc() Baoquan He
2022-02-19 7:13 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 16/22] usb: udc: lpc32xx: Don't use GFP_DMA " Baoquan He
2022-02-19 7:13 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 17/22] net: marvell: prestera: " Baoquan He
2022-02-19 4:54 ` Jakub Kicinski
2022-02-20 2:06 ` Baoquan He
2022-02-19 7:13 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 18/22] net: ethernet: mtk-star-emac: Don't use GFP_DMA when calling dmam_alloc_coherent() Baoquan He
2022-02-19 7:13 ` Christoph Hellwig
2022-02-19 0:52 ` Baoquan He [this message]
2022-02-19 7:14 ` [PATCH 19/22] ethernet: rocker: Use dma_alloc_noncoherent() for dma buffer Christoph Hellwig
2022-02-19 0:52 ` [PATCH 20/22] HID: intel-ish-hid: " Baoquan He
2022-02-19 7:14 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 21/22] mmc: wbsd: " Baoquan He
2022-02-19 7:17 ` Christoph Hellwig
2022-02-20 8:40 ` Baoquan He
2022-02-22 8:45 ` Christoph Hellwig
2022-02-22 9:14 ` Baoquan He
2022-02-22 13:11 ` Christoph Hellwig
2022-02-22 13:40 ` Baoquan He
2022-02-22 13:41 ` [PATCH 1/2] dma-mapping: check dma_mask for streaming mapping allocs Baoquan He
2022-02-22 15:59 ` Christoph Hellwig
2022-02-23 0:28 ` Baoquan He
2022-02-23 14:25 ` Christoph Hellwig
2022-02-23 14:57 ` David Laight
2022-02-24 14:11 ` Baoquan He
2022-02-24 14:27 ` David Laight
2022-02-25 15:39 ` 'Baoquan He'
2022-02-22 13:42 ` [PATCH 2/2] kernel/dma: rename dma_alloc_direct and dma_map_direct Baoquan He
2022-02-22 15:59 ` Christoph Hellwig
2022-02-19 0:52 ` [PATCH 22/22] mtd: rawnand: Use dma_alloc_noncoherent() for dma buffer Baoquan He
2022-02-19 7:19 ` Christoph Hellwig
2022-02-19 11:18 ` Hyeonggon Yoo
2022-02-22 8:46 ` Christoph Hellwig
2022-02-22 9:06 ` David Laight
2022-02-22 13:16 ` 'Christoph Hellwig'
2022-02-21 13:57 ` [PATCH 00/22] Don't use kmalloc() with GFP_DMA Heiko Carstens
2022-02-22 8:44 ` Christoph Hellwig
2022-02-22 13:12 ` Baoquan He
2022-02-22 13:26 ` Baoquan He
2022-02-23 19:18 ` Heiko Carstens
2022-02-24 6:33 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220219005221.634-20-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=42.hyeyoo@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=borntraeger@linux.ibm.com \
--cc=cl@linux.com \
--cc=davem@davemloft.net \
--cc=david@redhat.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hch@lst.de \
--cc=herbert@gondor.apana.org.au \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=michael@walle.cc \
--cc=netdev@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=steffen.klassert@secunet.com \
--cc=svens@linux.ibm.com \
--cc=vbabka@suse.cz \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).