diff mbox series

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

Message ID 20181206102105.53098-1-wen.yang99@zte.com.cn
State Not Applicable
Headers show
Series PCI: endpoint: functions: Use kmemdup instead of duplicating its function | expand

Commit Message

Wen Yang Dec. 6, 2018, 10:21 a.m. UTC
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(-)

Comments

Alan Douglas Dec. 6, 2018, noon UTC | #1
Hi,

On 06 December 2018 10:21, Wen Yang wrote:
> 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);
Looks like a typo - kmemdup instead of kzalloc?

>  	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

Regards,
Alan
David Laight Dec. 11, 2018, 2:22 p.m. UTC | #2
From: Alan Douglas
> Sent: 06 December 2018 12:01
> Hi,
> 
> On 06 December 2018 10:21, Wen Yang wrote:
> > kmemdup has implemented the function that kmalloc() + memcpy().
> > We prefer to kmemdup rather than code opened implementation.
...
> > 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);
> Looks like a typo - kmemdup instead of kzalloc?

Which is why making butter (churning) like this is mostly pointless.
It is very easy to make silly mistakes.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
diff mbox series

Patch

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;