.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
* @dev: the underlying device
const char *firmware, int len)
{
struct rproc *rproc;
- char *p, *template = "rproc-%s-fw";
- int name_len;
if (!dev || !name || !ops)
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);
- if (!rproc) {
- kfree(p);
+ if (!rproc)
return NULL;
- }
+
+ if (rproc_alloc_firmware(rproc, name, firmware))
+ goto free_rproc;
rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
- if (!rproc->ops) {
- kfree(p);
- kfree(rproc);
- return NULL;
- }
+ if (!rproc->ops)
+ goto free_firmware;
- rproc->firmware = p;
rproc->name = name;
rproc->priv = &rproc[1];
rproc->auto_boot = true;
rproc->state = RPROC_OFFLINE;
return rproc;
+
+free_firmware:
+ kfree(rproc->firmware);
+free_rproc:
+ kfree(rproc);
+ return NULL;
}
EXPORT_SYMBOL(rproc_alloc);