From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: bjorn.andersson@linaro.org, ohad@wizery.com
Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
Date: Wed, 15 Apr 2020 14:48:53 -0600 [thread overview]
Message-ID: <20200415204858.2448-3-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org>
Make the firmware name allocation a function on its own in an
effort to cleanup function rproc_alloc().
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
1 file changed, 39 insertions(+), 27 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 80056513ae71..4dee63f319ba 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
.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
@@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
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;
@@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
rproc->state = RPROC_OFFLINE;
return rproc;
+
+free_firmware:
+ kfree(rproc->firmware);
+free_rproc:
+ kfree(rproc);
+ return NULL;
}
EXPORT_SYMBOL(rproc_alloc);
--
2.20.1
next prev parent reply other threads:[~2020-04-15 20:49 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
2020-04-17 13:37 ` Suman Anna
2020-04-20 5:00 ` Bjorn Andersson
2020-04-15 20:48 ` Mathieu Poirier [this message]
2020-04-15 21:28 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Alex Elder
2020-04-20 5:09 ` Bjorn Andersson
2020-04-20 9:24 ` Arnaud POULIQUEN
2020-04-20 21:29 ` Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
2020-04-15 21:26 ` Alex Elder
2020-04-20 5:10 ` Bjorn Andersson
2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
2020-04-15 21:25 ` Alex Elder
2020-04-17 13:44 ` Suman Anna
2020-04-20 5:21 ` Bjorn Andersson
2020-04-17 16:12 ` [v2 4/7] remoteproc: Use kstrdup_const() rather than kstrdup() Markus Elfring
2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
2020-04-15 21:23 ` Alex Elder
2020-04-20 5:17 ` Bjorn Andersson
2020-04-16 6:26 ` Markus Elfring
2020-04-17 13:39 ` Suman Anna
2020-04-17 15:48 ` [v2 " Markus Elfring
2020-04-17 16:15 ` Suman Anna
2020-04-17 20:58 ` Mathieu Poirier
2020-04-17 21:28 ` [PATCH v2 " Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
2020-04-17 13:49 ` Suman Anna
2020-04-17 15:35 ` Suman Anna
2020-04-17 21:56 ` Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 7/7] remoteproc: Get rid of tedious error path Mathieu Poirier
2020-04-17 13:50 ` Suman Anna
2020-04-17 13:34 ` [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Suman Anna
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200415204858.2448-3-mathieu.poirier@linaro.org \
--to=mathieu.poirier@linaro.org \
--cc=Markus.Elfring@web.de \
--cc=bjorn.andersson@linaro.org \
--cc=elder@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=s-anna@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®