diff options
| author | Rolf Evers-Fischer <rolf.evers.fischer@aptiv.com> | 2018-02-28 12:32:18 -0500 |
|---|---|---|
| committer | Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> | 2018-03-01 06:58:18 -0500 |
| commit | 36cc14ac14c0d49d33820a82dab52a7edc802fef (patch) | |
| tree | e105a05c3ac92b47ff21872edb24f4eb1ea30746 /drivers/pci | |
| parent | 7928b2cbe55b2a410a0f5c1f154610059c57b1b2 (diff) | |
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: Rolf Evers-Fischer <rolf.evers.fischer@aptiv.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Diffstat (limited to 'drivers/pci')
| -rw-r--r-- | drivers/pci/endpoint/pci-epf-core.c | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 766ce1dca2ec..1f2506f32bb9 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c | |||
| @@ -200,8 +200,7 @@ struct pci_epf *pci_epf_create(const char *name) | |||
| 200 | int ret; | 200 | int ret; |
| 201 | struct pci_epf *epf; | 201 | struct pci_epf *epf; |
| 202 | struct device *dev; | 202 | struct device *dev; |
| 203 | char *func_name; | 203 | int len; |
| 204 | char *buf; | ||
| 205 | 204 | ||
| 206 | epf = kzalloc(sizeof(*epf), GFP_KERNEL); | 205 | epf = kzalloc(sizeof(*epf), GFP_KERNEL); |
| 207 | if (!epf) { | 206 | if (!epf) { |
| @@ -209,20 +208,11 @@ struct pci_epf *pci_epf_create(const char *name) | |||
| 209 | goto err_ret; | 208 | goto err_ret; |
| 210 | } | 209 | } |
| 211 | 210 | ||
| 212 | buf = kstrdup(name, GFP_KERNEL); | 211 | len = strchrnul(name, '.') - name; |
| 213 | if (!buf) { | 212 | epf->name = kstrndup(name, len, GFP_KERNEL); |
| 214 | ret = -ENOMEM; | ||
| 215 | goto free_epf; | ||
| 216 | } | ||
| 217 | |||
| 218 | func_name = buf; | ||
| 219 | buf = strchrnul(buf, '.'); | ||
| 220 | *buf = '\0'; | ||
| 221 | |||
| 222 | epf->name = kstrdup(func_name, GFP_KERNEL); | ||
| 223 | if (!epf->name) { | 213 | if (!epf->name) { |
| 224 | ret = -ENOMEM; | 214 | ret = -ENOMEM; |
| 225 | goto free_func_name; | 215 | goto free_epf; |
| 226 | } | 216 | } |
| 227 | 217 | ||
| 228 | dev = &epf->dev; | 218 | dev = &epf->dev; |
| @@ -238,16 +228,12 @@ struct pci_epf *pci_epf_create(const char *name) | |||
| 238 | if (ret) | 228 | if (ret) |
| 239 | goto put_dev; | 229 | goto put_dev; |
| 240 | 230 | ||
| 241 | kfree(func_name); | ||
| 242 | return epf; | 231 | return epf; |
| 243 | 232 | ||
| 244 | put_dev: | 233 | put_dev: |
| 245 | put_device(dev); | 234 | put_device(dev); |
| 246 | kfree(epf->name); | 235 | kfree(epf->name); |
| 247 | 236 | ||
| 248 | free_func_name: | ||
| 249 | kfree(func_name); | ||
| 250 | |||
| 251 | free_epf: | 237 | free_epf: |
| 252 | kfree(epf); | 238 | kfree(epf); |
| 253 | 239 | ||
