Skip to contentSkip to conversation

PCI: endpoint: functions: Use kmemdup instead of duplicating its function

PATCH Superseded Wen Yang 1 participant 1 message Dec 6, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 PCI: endpoint: functions: Use kmemdup instead of duplicating its function

kmemdup has implemented the function that kmalloc() + memcpy(). We prefer to kmemdup rather than code opened implementation.

This issue was detected with the help of coccinelle.

CC Bob Copeland <[email protected]>
CC Kishon Vijay Abraham I <[email protected]>
CC Lorenzo Pieralisi <[email protected]>
CC Bjorn Helgaas <[email protected]>
CC Gustavo Pimentel <[email protected]>
CC Niklas Cassel <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Cyrille Pitchen <[email protected]>
CC [email protected] (open list:PCI ENDPOINT SUBSYSTEM)
CC [email protected] (open list)
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -3
index 3e86fa3c7da3..8df6c019f8a2 100644
@@ -169,14 +169,12 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
 		goto err_addr;
 	}
 
-	buf = kzalloc(reg->size, GFP_KERNEL);
+	buf = kmemdup(src_addr, reg->size, GFP_KERNEL);
 	if (!buf) {
 		ret = -ENOMEM;
 		goto err_map_addr;
 	}
 
-	memcpy(buf, src_addr, reg->size);
-
 	crc32 = crc32_le(~0, buf, reg->size);
 	if (crc32 != reg->checksum)
 		ret = -EIO;
Signature · 1 line
2.19.1