Commit 36cc14ac authored by Rolf Evers-Fischer's avatar Rolf Evers-Fischer Committed by Lorenzo Pieralisi

PCI: endpoint: Simplify name allocation for EPF device

This commit replaces allocating and freeing the intermediate
'buf'/'func_name' with a combination of 'kstrndup()' and 'len'.

'len' is the required length of 'epf->name'.
'epf->name' should be either the first part of 'name' preceding the '.'
or the complete 'name', if there is no '.' in the name.
Signed-off-by: default avatarRolf Evers-Fischer <rolf.evers.fischer@aptiv.com>
Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
parent 7928b2cb
...@@ -200,8 +200,7 @@ struct pci_epf *pci_epf_create(const char *name) ...@@ -200,8 +200,7 @@ struct pci_epf *pci_epf_create(const char *name)
int ret; int ret;
struct pci_epf *epf; struct pci_epf *epf;
struct device *dev; struct device *dev;
char *func_name; int len;
char *buf;
epf = kzalloc(sizeof(*epf), GFP_KERNEL); epf = kzalloc(sizeof(*epf), GFP_KERNEL);
if (!epf) { if (!epf) {
...@@ -209,20 +208,11 @@ struct pci_epf *pci_epf_create(const char *name) ...@@ -209,20 +208,11 @@ struct pci_epf *pci_epf_create(const char *name)
goto err_ret; goto err_ret;
} }
buf = kstrdup(name, GFP_KERNEL); len = strchrnul(name, '.') - name;
if (!buf) { epf->name = kstrndup(name, len, GFP_KERNEL);
ret = -ENOMEM;
goto free_epf;
}
func_name = buf;
buf = strchrnul(buf, '.');
*buf = '\0';
epf->name = kstrdup(func_name, GFP_KERNEL);
if (!epf->name) { if (!epf->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_func_name; goto free_epf;
} }
dev = &epf->dev; dev = &epf->dev;
...@@ -238,16 +228,12 @@ struct pci_epf *pci_epf_create(const char *name) ...@@ -238,16 +228,12 @@ struct pci_epf *pci_epf_create(const char *name)
if (ret) if (ret)
goto put_dev; goto put_dev;
kfree(func_name);
return epf; return epf;
put_dev: put_dev:
put_device(dev); put_device(dev);
kfree(epf->name); kfree(epf->name);
free_func_name:
kfree(func_name);
free_epf: free_epf:
kfree(epf); kfree(epf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment