Commit 0f57dc6a authored by Matt Redfearn's avatar Matt Redfearn Committed by Bjorn Andersson

remoteproc: Keep local copy of firmware name

Storage of the firmware name was inconsistent, either storing a pointer
to a name stored with unknown ownership, or a variable length tacked
onto the end of the struct proc allocated in rproc_alloc.

In preparation for allowing the firmware of an already allocated struct
rproc to be changed, instead always keep a locally maintained copy of
the firmware name.
Signed-off-by: default avatarMatt Redfearn <matt.redfearn@imgtec.com>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent 1001354c
...@@ -1273,6 +1273,7 @@ static void rproc_type_release(struct device *dev) ...@@ -1273,6 +1273,7 @@ static void rproc_type_release(struct device *dev)
if (rproc->index >= 0) if (rproc->index >= 0)
ida_simple_remove(&rproc_dev_index, rproc->index); ida_simple_remove(&rproc_dev_index, rproc->index);
kfree(rproc->firmware);
kfree(rproc); kfree(rproc);
} }
...@@ -1310,31 +1311,31 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -1310,31 +1311,31 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
{ {
struct rproc *rproc; struct rproc *rproc;
char *p, *template = "rproc-%s-fw"; char *p, *template = "rproc-%s-fw";
int name_len = 0; int name_len;
if (!dev || !name || !ops) if (!dev || !name || !ops)
return NULL; return NULL;
if (!firmware) if (!firmware) {
/* /*
* Make room for default firmware name (minus %s plus '\0').
* If the caller didn't pass in a firmware name then * If the caller didn't pass in a firmware name then
* construct a default name. We're already glomming 'len' * construct a default name.
* bytes onto the end of the struct rproc allocation, so do
* a few more for the default firmware name (but only if
* the caller doesn't pass one).
*/ */
name_len = strlen(name) + strlen(template) - 2 + 1; name_len = strlen(name) + strlen(template) - 2 + 1;
p = kmalloc(name_len, GFP_KERNEL);
rproc = kzalloc(sizeof(*rproc) + len + name_len, GFP_KERNEL); if (!p)
if (!rproc) return NULL;
return NULL;
if (!firmware) {
p = (char *)rproc + sizeof(struct rproc) + len;
snprintf(p, name_len, template, name); snprintf(p, name_len, template, name);
} else { } else {
p = (char *)firmware; p = kstrdup(firmware, GFP_KERNEL);
if (!p)
return NULL;
}
rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
if (!rproc) {
kfree(p);
return NULL;
} }
rproc->firmware = p; rproc->firmware = p;
......
...@@ -415,7 +415,7 @@ struct rproc { ...@@ -415,7 +415,7 @@ struct rproc {
struct list_head node; struct list_head node;
struct iommu_domain *domain; struct iommu_domain *domain;
const char *name; const char *name;
const char *firmware; char *firmware;
void *priv; void *priv;
const struct rproc_ops *ops; const struct rproc_ops *ops;
struct device dev; struct device dev;
......
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