PCI: endpoint: use kmemdup_nul() in pci_epf_create()
Subsystems (2)
PATCH 1/1 PCI: endpoint: use kmemdup_nul() in pci_epf_create()
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 <[email protected]>
--- drivers/pci/endpoint/pci-epf-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +1 -1
@@ -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 );
Signature · 1 line
2.20.1
Quoted 4 lines · Chen Zhou
It is more efficient to use
kmemdup_nul()if the size is known exactly.The doc in kernel:
"Note: Usekmemdup_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.
Quoted 21 lines
Signed-off-by Chen Zhou <[email protected]>--- drivers/pci/endpoint/pci-epf-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/endpoint/pci-epf-core.c +1
-1@@ -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 );Signature · 1 line
2.20.1