All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: endpoint: functions: Use kmemdup instead of duplicating its function
@ 2018-12-06 10:21 Wen Yang
  2018-12-06 12:00 ` Alan Douglas
  0 siblings, 1 reply; 4+ messages in thread
From: Wen Yang @ 2018-12-06 10:21 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, zhong.weidong, Wen Yang, Bob Copeland,
	Gustavo Pimentel, Niklas Cassel, Greg Kroah-Hartman,
	Cyrille Pitchen

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.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
CC: Bob Copeland <me@bobcopeland.com>

CC: Kishon Vijay Abraham I <kishon@ti.com>
CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
CC: Bjorn Helgaas <bhelgaas@google.com>
CC: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
CC: Niklas Cassel <niklas.cassel@axis.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
CC: linux-pci@vger.kernel.org (open list:PCI ENDPOINT SUBSYSTEM)
CC: linux-kernel@vger.kernel.org (open list)
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 3e86fa3c7da3..6e42daa2a651 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -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 = kzalloc(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;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] PCI: endpoint: functions: Use kmemdup instead of duplicating its function
@ 2018-12-06 10:24 Wen Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Wen Yang @ 2018-12-06 10:24 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, zhong.weidong, Wen Yang, Bob Copeland,
	Gustavo Pimentel, Niklas Cassel, Greg Kroah-Hartman,
	Cyrille Pitchen

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.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
CC: Bob Copeland <me@bobcopeland.com>

CC: Kishon Vijay Abraham I <kishon@ti.com>
CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
CC: Bjorn Helgaas <bhelgaas@google.com>
CC: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
CC: Niklas Cassel <niklas.cassel@axis.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
CC: linux-pci@vger.kernel.org (open list:PCI ENDPOINT SUBSYSTEM)
CC: linux-kernel@vger.kernel.org (open list)
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 3e86fa3c7da3..8df6c019f8a2 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -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;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-11 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 10:21 [PATCH] PCI: endpoint: functions: Use kmemdup instead of duplicating its function Wen Yang
2018-12-06 12:00 ` Alan Douglas
2018-12-11 14:22   ` David Laight
2018-12-06 10:24 Wen Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.