All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] PCI: endpoint: use kmemdup_nul() in pci_epf_create()
@ 2020-05-08 12:10 Chen Zhou
  2020-05-08 16:23 ` Bjorn Helgaas
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Zhou @ 2020-05-08 12:10 UTC (permalink / raw)
  To: kishon, lorenzo.pieralisi, bhelgaas; +Cc: linux-pci, linux-kernel, chenzhou10

It is more efficient to use kmemdup_nul() if the size is known exactly.

The doc in kernel:
"Note: Use kmemdup_nul() instead if the size is known exactly."

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 drivers/pci/endpoint/pci-epf-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 244e00f48c5c..f035d2ebcae5 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -252,7 +252,7 @@ struct pci_epf *pci_epf_create(const char *name)
 		return ERR_PTR(-ENOMEM);
 
 	len = strchrnul(name, '.') - name;
-	epf->name = kstrndup(name, len, GFP_KERNEL);
+	epf->name = kmemdup_nul(name, len, GFP_KERNEL);
 	if (!epf->name) {
 		kfree(epf);
 		return ERR_PTR(-ENOMEM);
-- 
2.20.1


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

* Re: [PATCH -next] PCI: endpoint: use kmemdup_nul() in pci_epf_create()
  2020-05-08 12:10 [PATCH -next] PCI: endpoint: use kmemdup_nul() in pci_epf_create() Chen Zhou
@ 2020-05-08 16:23 ` Bjorn Helgaas
  0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2020-05-08 16:23 UTC (permalink / raw)
  To: Chen Zhou; +Cc: kishon, lorenzo.pieralisi, bhelgaas, linux-pci, linux-kernel

On Fri, May 08, 2020 at 08:10:29PM +0800, Chen Zhou wrote:
> It is more efficient to use kmemdup_nul() if the size is known exactly.
> 
> The doc in kernel:
> "Note: Use kmemdup_nul() instead if the size is known exactly."

If you want to do this, I want to do at least the entire drivers/pci
directory at once so we don't have a bunch of onesy-twosy patches.  It
looks like there's at least one more potential change in
pci_dev_str_match_path().

Also, please mention that the doc is from the kstrndup() function
comment.

> Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
> ---
>  drivers/pci/endpoint/pci-epf-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
> index 244e00f48c5c..f035d2ebcae5 100644
> --- a/drivers/pci/endpoint/pci-epf-core.c
> +++ b/drivers/pci/endpoint/pci-epf-core.c
> @@ -252,7 +252,7 @@ struct pci_epf *pci_epf_create(const char *name)
>  		return ERR_PTR(-ENOMEM);
>  
>  	len = strchrnul(name, '.') - name;
> -	epf->name = kstrndup(name, len, GFP_KERNEL);
> +	epf->name = kmemdup_nul(name, len, GFP_KERNEL);
>  	if (!epf->name) {
>  		kfree(epf);
>  		return ERR_PTR(-ENOMEM);
> -- 
> 2.20.1
> 

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

end of thread, other threads:[~2020-05-08 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 12:10 [PATCH -next] PCI: endpoint: use kmemdup_nul() in pci_epf_create() Chen Zhou
2020-05-08 16:23 ` Bjorn Helgaas

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.