Commit 0c2ae2b1 authored by Mathieu Poirier's avatar Mathieu Poirier Committed by Bjorn Andersson

remoteproc: Split firmware name allocation from rproc_alloc()

Make the firmware name allocation a function on its own in an
effort to cleanup function rproc_alloc().
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Link: https://lore.kernel.org/r/20200415204858.2448-3-mathieu.poirier@linaro.orgSigned-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent 6442df49
...@@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = { ...@@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
.release = rproc_type_release, .release = rproc_type_release,
}; };
static int rproc_alloc_firmware(struct rproc *rproc,
const char *name, const char *firmware)
{
char *p, *template = "rproc-%s-fw";
int name_len;
if (!firmware) {
/*
* If the caller didn't pass in a firmware name then
* construct a default name.
*/
name_len = strlen(name) + strlen(template) - 2 + 1;
p = kmalloc(name_len, GFP_KERNEL);
if (!p)
return -ENOMEM;
snprintf(p, name_len, template, name);
} else {
p = kstrdup(firmware, GFP_KERNEL);
if (!p)
return -ENOMEM;
}
rproc->firmware = p;
return 0;
}
/** /**
* rproc_alloc() - allocate a remote processor handle * rproc_alloc() - allocate a remote processor handle
* @dev: the underlying device * @dev: the underlying device
...@@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
const char *firmware, int len) const char *firmware, int len)
{ {
struct rproc *rproc; struct rproc *rproc;
char *p, *template = "rproc-%s-fw";
int name_len;
if (!dev || !name || !ops) if (!dev || !name || !ops)
return NULL; return NULL;
if (!firmware) {
/*
* If the caller didn't pass in a firmware name then
* construct a default name.
*/
name_len = strlen(name) + strlen(template) - 2 + 1;
p = kmalloc(name_len, GFP_KERNEL);
if (!p)
return NULL;
snprintf(p, name_len, template, name);
} else {
p = kstrdup(firmware, GFP_KERNEL);
if (!p)
return NULL;
}
rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
if (!rproc) { if (!rproc)
kfree(p);
return NULL; return NULL;
}
if (rproc_alloc_firmware(rproc, name, firmware))
goto free_rproc;
rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
if (!rproc->ops) { if (!rproc->ops)
kfree(p); goto free_firmware;
kfree(rproc);
return NULL;
}
rproc->firmware = p;
rproc->name = name; rproc->name = name;
rproc->priv = &rproc[1]; rproc->priv = &rproc[1];
rproc->auto_boot = true; rproc->auto_boot = true;
...@@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
rproc->state = RPROC_OFFLINE; rproc->state = RPROC_OFFLINE;
return rproc; return rproc;
free_firmware:
kfree(rproc->firmware);
free_rproc:
kfree(rproc);
return NULL;
} }
EXPORT_SYMBOL(rproc_alloc); EXPORT_SYMBOL(rproc_alloc);
......
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