RE: [PATCH 12/13] remoteproc: Refactor rproc delete and cdev release path
From: Peng Fan
Date: Wed Oct 14 2020 - 22:35:47 EST
> Subject: [PATCH 12/13] remoteproc: Refactor rproc delete and cdev release
> path
>
> Refactor function rproc_del() and rproc_cdev_release() to take into account
> scenarios where the remote processor has been attached to. If the remote
> processor has been started by the remoteproc core then switch it off, and if it
> was attached to detach from it. This heuristic is simple and can be enhanced
> easily if there is a need to.
>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@xxxxxxxxxx>
> ---
> drivers/remoteproc/remoteproc_cdev.c | 7 ++++++-
> drivers/remoteproc/remoteproc_core.c | 5 ++++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_cdev.c
> b/drivers/remoteproc/remoteproc_cdev.c
> index 3a3830e27050..18cffbe588c1 100644
> --- a/drivers/remoteproc/remoteproc_cdev.c
> +++ b/drivers/remoteproc/remoteproc_cdev.c
> @@ -87,8 +87,13 @@ static int rproc_cdev_release(struct inode *inode,
> struct file *filp) {
> struct rproc *rproc = container_of(inode->i_cdev, struct rproc, cdev);
>
> - if (rproc->cdev_put_on_release && rproc->state == RPROC_RUNNING)
> + if (!rproc->cdev_put_on_release)
> + return 0;
> +
> + if (rproc->state == RPROC_RUNNING)
> rproc_shutdown(rproc);
> + else if (rproc->state == RPROC_ATTACHED)
> + rproc_detach(rproc);
>
> return 0;
> }
> diff --git a/drivers/remoteproc/remoteproc_core.c
> b/drivers/remoteproc/remoteproc_core.c
> index 95bb40b4ebb3..5586582f54c5 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2346,7 +2346,10 @@ int rproc_del(struct rproc *rproc)
> return -EINVAL;
>
> /* TODO: make sure this works with rproc->power > 1 */
> - rproc_shutdown(rproc);
> + if (rproc->state == RPROC_RUNNING)
> + rproc_shutdown(rproc);
> + else if (rproc->state == RPROC_ATTACHED)
> + rproc_detach(rproc);
>
> mutex_lock(&rproc->lock);
> rproc->state = RPROC_DELETED;
> --
Reviewed-by: Peng Fan <peng.fan@xxxxxxx>