[PATCH v3 02/14] remoteproc: Introduce function rproc_alloc_internals()

From: Mathieu Poirier
Date: Fri Apr 24 2020 - 16:01:45 EST


In scenarios where the remote processor's lifecycle is entirely
managed by another entity there is no point in allocating memory for
a firmware name since it will never be used. The same goes for a core
set of operations.

As such introduce function rproc_alloc_internals() to decide if the
allocation of a firmware name and the core operations need to be done.
That way rproc_alloc() can be kept as clean as possible.

Signed-off-by: Mathieu Poirier <mathieu.poirier@xxxxxxxxxx>
---
drivers/remoteproc/remoteproc_core.c | 31 +++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 448262470fc7..1b4756909584 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2076,6 +2076,30 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)
return 0;
}

+static int rproc_alloc_internals(struct rproc *rproc,
+ const struct rproc_ops *ops,
+ const char *name, const char *firmware)
+{
+ int ret;
+
+ /*
+ * In scenarios where the remote processor's lifecycle is entirely
+ * managed by another entity there is no point in carrying a set
+ * of operations that will never be used.
+ *
+ * And since no firmware will ever be loaded, there is no point in
+ * allocating memory for it either.
+ */
+ if (!ops)
+ return 0;
+
+ ret = rproc_alloc_firmware(rproc, name, firmware);
+ if (ret)
+ return ret;
+
+ return rproc_alloc_ops(rproc, ops);
+}
+
/**
* rproc_alloc() - allocate a remote processor handle
* @dev: the underlying device
@@ -2105,7 +2129,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
{
struct rproc *rproc;

- if (!dev || !name || !ops)
+ if (!dev || !name)
return NULL;

rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
@@ -2128,10 +2152,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
if (!rproc->name)
goto put_device;

- if (rproc_alloc_firmware(rproc, name, firmware))
- goto put_device;
-
- if (rproc_alloc_ops(rproc, ops))
+ if (rproc_alloc_internals(rproc, ops, name, firmware))
goto put_device;

/* Assign a unique device index and name */
--
2.20.1