[PATCH v3] remoteproc: k3-dsp: Fix an error handling path in k3_dsp_rproc_probe()

Christophe JAILLET posted 1 patch 2 months, 2 weeks ago
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
[PATCH v3] remoteproc: k3-dsp: Fix an error handling path in k3_dsp_rproc_probe()
Posted by Christophe JAILLET 2 months, 2 weeks ago
If an error occurs after mbox_request_channel() in
k3_dsp_rproc_request_mbox(), mbox_free_channel() must be called,
as already done in the remove function.

Instead of adding an error handling path in the probe and changing all
error handling in the function, add a new devm_add_action_or_reset() and
simplify the error handling path of k3_dsp_rproc_request_mbox() and the
.remove() function.

Fixes: ea1d6fb5b571 ("remoteproc: k3-dsp: Acquire mailbox handle during probe routine")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Davis <afd@ti.com>
---
Compile tested only.

Change in v3:
  - pass the correct variable to devm_add_action_or_reset()   [Mathieu Poirier]
  - move the devm_add_action_or_reset() call just after
    mbox_request_channel() and simplify error handling in
    k3_dsp_rproc_request_mbox()
  - Because of these changes, remove previous R-b tag

Change in v2:
  - fix the subject (cut'n'paste issue)   [Andrew Davis]
  - add R-b tag

v1: https://lore.kernel.org/all/9485e127a00419c76cf13dbccf4874af395ef6ba.1725653543.git.christophe.jaillet@wanadoo.fr/
---
 drivers/remoteproc/ti_k3_dsp_remoteproc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index 8be3f631c192..f0da29fa7f60 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -224,6 +224,13 @@ static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc)
 	return ret;
 }
 
+static void k3_dsp_free_channel(void *data)
+{
+	struct k3_dsp_rproc *kproc = data;
+
+	mbox_free_channel(kproc->mbox);
+}
+
 static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
 {
 	struct k3_dsp_rproc *kproc = rproc->priv;
@@ -242,6 +249,10 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
 		return dev_err_probe(dev, PTR_ERR(kproc->mbox),
 				     "mbox_request_channel failed\n");
 
+	ret = devm_add_action_or_reset(dev, k3_dsp_free_channel, kproc);
+	if (ret)
+		return ret;
+
 	/*
 	 * Ping the remote processor, this is only for sanity-sake for now;
 	 * there is no functional effect whatsoever.
@@ -252,7 +263,6 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
 	ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
 	if (ret < 0) {
 		dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
-		mbox_free_channel(kproc->mbox);
 		return ret;
 	}
 
@@ -741,8 +751,6 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)
 		if (ret)
 			dev_err(dev, "failed to detach proc (%pe)\n", ERR_PTR(ret));
 	}
-
-	mbox_free_channel(kproc->mbox);
 }
 
 static const struct k3_dsp_mem_data c66_mems[] = {
-- 
2.46.0