rproc_del() is subjected to the reference counted shutdown path, as such a remoteproc with more than one reference will be left running as its resources are released underneath it.
Refactor the shutdown path such that the reference count value is ignored when called from rproc_del(). Assisted-by: OpenCode:GPT-5.5 Signed-off-by: Bjorn Andersson <[email protected]> --- drivers/remoteproc/remoteproc_core.c | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 899d2058bc45..1ed406714849 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1988,28 +1988,7 @@ int rproc_boot(struct rproc *rproc) } EXPORT_SYMBOL(rproc_boot); -/** - * rproc_shutdown() - power off the remote processor - * @rproc: the remote processor - * - * Power off a remote processor (previously booted with rproc_boot()). - * - * In case @rproc is still being used by an additional user(s), then - * this function will just decrement the power refcount and exit, - * without really powering off the device. - * - * Every call to rproc_boot() must (eventually) be accompanied by a call - * to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug. - * - * Notes: - * - we're not decrementing the rproc's refcount, only the power refcount. - * which means that the @rproc handle stays valid even after rproc_shutdown() - * returns, and users can still use it with a subsequent rproc_boot(), if - * needed. - * - * Return: 0 on success, and an appropriate error value otherwise - */ -int rproc_shutdown(struct rproc *rproc) +static int __rproc_shutdown(struct rproc *rproc, bool force) { struct device *dev = &rproc->dev; bool crashed; @@ -2029,9 +2008,10 @@ int rproc_shutdown(struct rproc *rproc) } crashed = rproc->state == RPROC_CRASHED; - /* if the remote proc is still needed, bail out */ - if (!atomic_dec_and_test(&rproc->power)) + if (!atomic_dec_and_test(&rproc->power) && !force) { + /* The remote processor is still needed by another user. */ goto out; + } ret = rproc_stop(rproc, crashed); if (ret) { @@ -2055,6 +2035,32 @@ int rproc_shutdown(struct rproc *rproc) mutex_unlock(&rproc->lock); return ret; } + +/** + * rproc_shutdown() - power off the remote processor + * @rproc: the remote processor + * + * Power off a remote processor (previously booted with rproc_boot()). + * + * In case @rproc is still being used by an additional user(s), then + * this function will just decrement the power refcount and exit, + * without really powering off the device. + * + * Every call to rproc_boot() must (eventually) be accompanied by a call + * to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug. + * + * Notes: + * - we're not decrementing the rproc's refcount, only the power refcount. + * which means that the @rproc handle stays valid even after rproc_shutdown() + * returns, and users can still use it with a subsequent rproc_boot(), if + * needed. + * + * Return: 0 on success, and an appropriate error value otherwise + */ +int rproc_shutdown(struct rproc *rproc) +{ + return __rproc_shutdown(rproc, false); +} EXPORT_SYMBOL(rproc_shutdown); /** @@ -2621,8 +2627,7 @@ int rproc_del(struct rproc *rproc) if (cancel_work_sync(&rproc->crash_handler)) pm_relax(rproc->dev.parent); - /* TODO: make sure this works with rproc->power > 1 */ - rproc_shutdown(rproc); + __rproc_shutdown(rproc, true); rproc_delete_debug_dir(rproc); -- 2.53.0

