All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: bjorn.andersson@linaro.org, ohad@wizery.com
Cc: s-anna@ti.com, elder@linaro.org,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] remoteproc: Get rid of tedious error path
Date: Mon, 13 Apr 2020 13:34:01 -0600	[thread overview]
Message-ID: <20200413193401.27234-5-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <20200413193401.27234-1-mathieu.poirier@linaro.org>

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>
---
 drivers/remoteproc/remoteproc_core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index c272d78f07e8..10009b95867a 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2061,12 +2061,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	if (!rproc)
 		return NULL;
 
-	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;
@@ -2079,12 +2073,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->dev.driver_data = rproc;
 	idr_init(&rproc->notifyids);
 
+	if (rproc_alloc_firmware(rproc, name, firmware))
+		goto out;
+
+	if (rproc_alloc_ops(rproc, ops))
+		goto out;
+
 	/* 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;
+		goto out;
 	}
 
 	dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
@@ -2105,11 +2104,8 @@ 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);
+out:
+	put_device(&rproc->dev);
 	return NULL;
 }
 EXPORT_SYMBOL(rproc_alloc);
-- 
2.20.1

  parent reply	other threads:[~2020-04-13 19:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 19:33 [PATCH 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-13 19:33 ` [PATCH 1/4] remoteproc: Fix a bug in rproc_alloc() Mathieu Poirier
2020-04-13 19:33 ` [PATCH 2/4] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
2020-04-13 20:56   ` Alex Elder
2020-04-14  0:55     ` Bjorn Andersson
2020-04-14  0:55       ` Bjorn Andersson
2020-04-14  0:55         ` Bjorn Andersson
2020-04-14 12:36         ` Alex Elder
2020-04-14 15:43         ` Mathieu Poirier
2020-04-14 19:48           ` Bjorn Andersson
2020-04-14 19:48             ` Bjorn Andersson
2020-04-14 19:48               ` Bjorn Andersson
2020-04-14 19:44         ` Mathieu Poirier
2020-04-14 23:16           ` Bjorn Andersson
2020-04-14 23:16             ` Bjorn Andersson
2020-04-14 23:16               ` Bjorn Andersson
2020-04-15 19:34               ` Mathieu Poirier
2020-04-14 16:11     ` Mathieu Poirier
2020-04-13 19:34 ` [PATCH 3/4] remoteproc: Split rproc_ops " Mathieu Poirier
2020-04-13 20:56   ` Alex Elder
2020-04-13 19:34 ` Mathieu Poirier [this message]
2020-04-13 20:56   ` [PATCH 4/4] remoteproc: Get rid of tedious error path Alex Elder
2020-04-13 20:56   ` Alex Elder
2020-04-14  8:53 Markus Elfring
2020-04-14 12:27 ` Alex Elder

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=20200413193401.27234-5-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.