PCI: endpoint: functions: Use kmemdup instead of duplicating its function
Subsystems (2)
PATCH v2 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.
--- 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
@@ -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
Quoted 15 lines · Wen Yang
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 <[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)
Quoted 3 lines
--- drivers/pci/endpoint/functions/pci-epf-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Kishon,
this looks OK to me, anything I am missing ?
Lorenzo
Quoted 23 lines
drivers/pci/endpoint/functions/pci-epf-test.c +1
-3@@ -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
Hi Lorenzo,
Quoted 20 lines · Lorenzo Pieralisi
Quoted 15 lines · Wen Yang
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 <[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)Quoted 3 lines
--- drivers/pci/endpoint/functions/pci-epf-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 3 lines
Kishon,
this looks OK to me, anything I am missing ?
For the existing code this might seem the right thing to do but ideally the memcpy here should be changed to memcpy_fromio/memcpy_toio.
Also later when we plan to use DMA (on the endpoint) for data transfer, we have to use kzalloc and dma_map_single APIs.
So maybe the right thing would be to just fix it to use memcpy_fromio here.
Thanks
Kishon
Quoted 26 lines
Lorenzo
Quoted 23 lines
drivers/pci/endpoint/functions/pci-epf-test.c +1
-3@@ -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
Quoted 25 lines · Kishon Vijay Abraham I
Hi Lorenzo,
Quoted 22 lines · Lorenzo Pieralisi
Quoted 15 lines · Wen Yang
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 <[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)Quoted 3 lines
--- drivers/pci/endpoint/functions/pci-epf-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)Kishon,
Quoted 7 lines
Quoted 1 line
this looks OK to me, anything I am missing ?
For the existing code this might seem the right thing to do but ideally the memcpy here should be changed to memcpy_fromio/memcpy_toio.
Also later when we plan to use DMA (on the endpoint) for data transfer, we have to use kzalloc and
dma_map_singleAPIs.
Are you considering to use the eDMA driver that I'm developing?
Quoted 31 lines
So maybe the right thing would be to just fix it to use
memcpy_fromiohere.Thanks
KishonQuoted 26 lines
Lorenzo
Quoted 23 lines
drivers/pci/endpoint/functions/pci-epf-test.c +1
-3@@ -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
Hi Gustavo,
Quoted 28 lines · Gustavo Pimentel
Quoted 27 lines · Kishon Vijay Abraham I
Hi Lorenzo,
Quoted 23 lines · Lorenzo Pieralisi
Quoted 15 lines · Wen Yang
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 <[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)Quoted 3 lines
--- drivers/pci/endpoint/functions/pci-epf-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)Kishon,
this looks OK to me, anything I am missing ?
Quoted 7 lines
Quoted 5 lines
For the existing code this might seem the right thing to do but ideally the memcpy here should be changed to memcpy_fromio/memcpy_toio.
Also later when we plan to use DMA (on the endpoint) for data transfer, we have to use kzalloc and
dma_map_singleAPIs.Are you considering to use the eDMA driver that I'm developing?
I used system DMA for my testing. But in the DesignWare driver, we should be able to choose between system DMA or any other DMA based on the platforms capabilities.
Thanks
Kishon