[PATCH v2 4/4] remoteproc: core: Clean up after a failed recovery

From: Yonghao Zhang

Date: Tue Nov 24 2026 - 02:15:06 EST


Release the resources on the failure paths of rproc_boot_recovery(),
the same way rproc_shutdown() does, and void the power count in
rproc_trigger_recovery() when a failed recovery leaves the processor
offline or detached.

Fixes: ba194232edc0 ("remoteproc: Support attach recovery after rproc crash")
Signed-off-by: Yonghao Zhang <hyz3367@xxxxxxxxx>
---
drivers/remoteproc/remoteproc_core.c | 31 +++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 8c3fc85b8f04..3e700c94110d 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1800,7 +1800,7 @@ static int rproc_boot_recovery(struct rproc *rproc)
ret = request_firmware(&firmware_p, rproc->firmware, dev);
if (ret < 0) {
dev_err(dev, "request_firmware failed: %d\n", ret);
- return ret;
+ goto clean_up_resources;
}

/* boot the remote processor up again */
@@ -1808,6 +1808,24 @@ static int rproc_boot_recovery(struct rproc *rproc)

release_firmware(firmware_p);

+ if (ret < 0)
+ goto clean_up_resources;
+
+ return 0;
+
+clean_up_resources:
+ /*
+ * rproc_stop() has already switched the remote processor off;
+ * release the resources of the boot this recovery was trying to
+ * restore.
+ */
+ rproc_resource_cleanup(rproc);
+ /* release HW resources if needed */
+ rproc_unprepare_device(rproc);
+ rproc_disable_iommu(rproc);
+ kfree(rproc->cached_table);
+ rproc->cached_table = NULL;
+ rproc->table_ptr = NULL;
return ret;
}

@@ -1848,6 +1866,17 @@ int rproc_trigger_recovery(struct rproc *rproc)
else
ret = rproc_boot_recovery(rproc);

+ /*
+ * A failed recovery leaves the remote processor offline or
+ * detached, where rproc_shutdown() cannot release the power
+ * references: void them.
+ */
+ if (ret && (rproc->state == RPROC_OFFLINE ||
+ rproc->state == RPROC_DETACHED)) {
+ dev_err(dev, "failed to recover %s: %d\n", rproc->name, ret);
+ atomic_set(&rproc->power, 0);
+ }
+
unlock_mutex:
mutex_unlock(&rproc->lock);
return ret;
--
2.34.1