Get rid of tedious error management by moving firmware and operation
allocation after calling device_initialize(). That way we take advantage
of the automatic call to rproc_type_release() to cleanup after ourselves
when put_device() is called.
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: Suman Anna <s-anna@ti.com>
Link: https://lore.kernel.org/r/20200420231601.16781-5-mathieu.poirier@linaro.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
- if (rproc_alloc_firmware(rproc, name, firmware))
- goto free_rproc;
-
- if (rproc_alloc_ops(rproc, ops))
- goto free_firmware;
-
rproc->name = name;
rproc->priv = &rproc[1];
rproc->auto_boot = true;
rproc->name = name;
rproc->priv = &rproc[1];
rproc->auto_boot = true;
rproc->dev.driver_data = rproc;
idr_init(&rproc->notifyids);
rproc->dev.driver_data = rproc;
idr_init(&rproc->notifyids);
+ if (rproc_alloc_firmware(rproc, name, firmware))
+ goto put_device;
+
+ if (rproc_alloc_ops(rproc, ops))
+ goto put_device;
+
/* Assign a unique device index and name */
rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
if (rproc->index < 0) {
dev_err(dev, "ida_simple_get failed: %d\n", rproc->index);
/* Assign a unique device index and name */
rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
if (rproc->index < 0) {
dev_err(dev, "ida_simple_get failed: %d\n", rproc->index);
- put_device(&rproc->dev);
- return NULL;
}
dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
}
dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
-free_firmware:
- kfree_const(rproc->firmware);
-free_rproc:
- kfree(rproc);
+put_device:
+ put_device(&rproc->dev);
return NULL;
}
EXPORT_SYMBOL(rproc_alloc);
return NULL;
}
EXPORT_SYMBOL(rproc_alloc);