Re: [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc()

From: Suman Anna
Date: Fri Apr 17 2020 - 11:35:56 EST


On 4/17/20 8:49 AM, Suman Anna wrote:
On 4/15/20 3:48 PM, Mathieu Poirier wrote:
Make the rproc_ops allocation a function on its own in an effort
to clean up function rproc_alloc().

Signed-off-by: Mathieu Poirier <mathieu.poirier@xxxxxxxxxx>
Reviewed-by: Alex Elder <elder@xxxxxxxxxx>
---
 drivers/remoteproc/remoteproc_core.c | 32 +++++++++++++++++-----------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 0bfa6998705d..a5a0ceb86b3f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2001,6 +2001,25 @@ static int rproc_alloc_firmware(struct rproc *rproc,
ÂÂÂÂÂ return 0;
 }
+static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)
+{
+ÂÂÂ rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
+ÂÂÂ if (!rproc->ops)
+ÂÂÂÂÂÂÂ return -ENOMEM;
+
+ÂÂÂ /* Default to ELF loader if no load function is specified */
+ÂÂÂ if (!rproc->ops->load) {
+ÂÂÂÂÂÂÂ rproc->ops->load = rproc_elf_load_segments;
+ÂÂÂÂÂÂÂ rproc->ops->parse_fw = rproc_elf_load_rsc_table;
+ÂÂÂÂÂÂÂ rproc->ops->find_loaded_rsc_table =
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rproc_elf_find_loaded_rsc_table;
+ÂÂÂÂÂÂÂ rproc->ops->sanity_check = rproc_elf_sanity_check;

So, the conditional check on sanity check is dropped and the callback switched here without the changelog reflecting anything why. You should just rebase this patch on top of Clement's patch [1] that removes the conditional flag, and also usage from the remoteproc platform drivers.

regards
Suman

[1] https://patchwork.kernel.org/patch/11462013/

Sorry, gave the wrong link, that was v1. This is the latest,
https://patchwork.kernel.org/patch/11466955/



+ÂÂÂÂÂÂÂ rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
+ÂÂÂ }
+
+ÂÂÂ return 0;
+}
+
 /**
ÂÂ * rproc_alloc() - allocate a remote processor handle
ÂÂ * @dev: the underlying device
@@ -2040,8 +2059,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
ÂÂÂÂÂ if (rproc_alloc_firmware(rproc, name, firmware))
ÂÂÂÂÂÂÂÂÂ goto free_rproc;
-ÂÂÂ rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
-ÂÂÂ if (!rproc->ops)
+ÂÂÂ if (rproc_alloc_ops(rproc, ops))
ÂÂÂÂÂÂÂÂÂ goto free_firmware;
ÂÂÂÂÂ rproc->name = name;
@@ -2068,16 +2086,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
ÂÂÂÂÂ atomic_set(&rproc->power, 0);
-ÂÂÂ /* Default to ELF loader if no load function is specified */
-ÂÂÂ if (!rproc->ops->load) {
-ÂÂÂÂÂÂÂ rproc->ops->load = rproc_elf_load_segments;
-ÂÂÂÂÂÂÂ rproc->ops->parse_fw = rproc_elf_load_rsc_table;
-ÂÂÂÂÂÂÂ rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
-ÂÂÂÂÂÂÂ if (!rproc->ops->sanity_check)
-ÂÂÂÂÂÂÂÂÂÂÂ rproc->ops->sanity_check = rproc_elf32_sanity_check;
-ÂÂÂÂÂÂÂ rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
-ÂÂÂ }
-
ÂÂÂÂÂ mutex_init(&rproc->lock);
ÂÂÂÂÂ INIT_LIST_HEAD(&rproc->carveouts);