@@ -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[] = {