All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghao Zhang <hyz3367@gmail.com>
To: mathieu.poirier@linaro.org, andersson@kernel.org
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yonghao Zhang <hyz3367@gmail.com>
Subject: [PATCH v2 4/4] remoteproc: core: Clean up after a failed recovery
Date: Tue, 24 Nov 2026 15:14:09 +0800	[thread overview]
Message-ID: <20261124071409.972-5-hyz3367@gmail.com> (raw)
In-Reply-To: <20261124071409.972-1-hyz3367@gmail.com>

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@gmail.com>
---
 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


      parent reply	other threads:[~2026-11-24  7:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  7:14 [PATCH v2 0/4] remoteproc: core: Fix the error unwind paths Yonghao Zhang
2026-11-24  7:14 ` [PATCH v2 1/4] remoteproc: core: Reset freed vring entries to FW_RSC_ADDR_ANY Yonghao Zhang
2026-11-24  7:14 ` [PATCH v2 2/4] remoteproc: core: Guard against a missing stop() in rproc_start() Yonghao Zhang
2026-11-24  7:14 ` [PATCH v2 3/4] remoteproc: core: Guard against a missing stop() in the attach unwind Yonghao Zhang
2026-11-24  7:14 ` Yonghao Zhang [this message]

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=20261124071409.972-5-hyz3367@gmail.com \
    --to=hyz3367@gmail.com \
    --cc=andersson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    /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.