diff mbox series

thunderbolt: Use kmemdup instead of kzmalloc and memcpy

Message ID 1608686793-52044-1-git-send-email-tiantao6@hisilicon.com
State New
Headers show
Series thunderbolt: Use kmemdup instead of kzmalloc and memcpy | expand

Commit Message

Tian Tao Dec. 23, 2020, 1:26 a.m. UTC
Fixes coccicheck warning:
drivers/thunderbolt/dma_test.c:302:13-20: WARNING opportunity for kmemdup.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/thunderbolt/dma_test.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Mika Westerberg Dec. 28, 2020, 9:46 a.m. UTC | #1
On Wed, Dec 23, 2020 at 09:26:33AM +0800, Tian Tao wrote:
> Fixes coccicheck warning:

> drivers/thunderbolt/dma_test.c:302:13-20: WARNING opportunity for kmemdup.

> 

> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>


Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/thunderbolt/dma_test.c b/drivers/thunderbolt/dma_test.c
index f924423..955f980 100644
--- a/drivers/thunderbolt/dma_test.c
+++ b/drivers/thunderbolt/dma_test.c
@@ -299,14 +299,12 @@  static int dma_test_submit_tx(struct dma_test *dt, size_t npackets)
 		tf->frame.size = 0; /* means 4096 */
 		tf->dma_test = dt;
 
-		tf->data = kzalloc(DMA_TEST_FRAME_SIZE, GFP_KERNEL);
+		tf->data = kmemdup(dma_test_pattern, DMA_TEST_FRAME_SIZE, GFP_KERNEL);
 		if (!tf->data) {
 			kfree(tf);
 			return -ENOMEM;
 		}
 
-		memcpy(tf->data, dma_test_pattern, DMA_TEST_FRAME_SIZE);
-
 		dma_addr = dma_map_single(dma_dev, tf->data, DMA_TEST_FRAME_SIZE,
 					  DMA_TO_DEVICE);
 		if (dma_mapping_error(dma_dev, dma_addr)) {