[PATCH v4 12/12] remoteproc: imx_dsp_rproc: simplify start/stop error handling

Peng Fan (OSS) posted 12 patches 1 week, 5 days ago
[PATCH v4 12/12] remoteproc: imx_dsp_rproc: simplify start/stop error handling
Posted by Peng Fan (OSS) 1 week, 5 days ago
From: Peng Fan <peng.fan@nxp.com>

Replace goto-based error handling with early return pattern in
imx_dsp_rproc_{start,stop}() functions, and simplify if-else logic.

No functional changes, only code structure improvements for better
maintainability.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/remoteproc/imx_dsp_rproc.c | 39 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c
index 6237e8db2eff759c2b7fcce5fb4a44e4ebaec8cf..1a1438823e7fc0a65ba15142abdd97e59692801c 100644
--- a/drivers/remoteproc/imx_dsp_rproc.c
+++ b/drivers/remoteproc/imx_dsp_rproc.c
@@ -376,20 +376,19 @@ static int imx_dsp_rproc_start(struct rproc *rproc)
 	struct device *dev = rproc->dev.parent;
 	int ret;
 
-	if (dcfg->ops && dcfg->ops->start) {
-		ret = dcfg->ops->start(rproc);
-		goto start_ret;
-	}
-
-	return -EOPNOTSUPP;
+	if (!dcfg->ops || !dcfg->ops->start)
+		return -EOPNOTSUPP;
 
-start_ret:
-	if (ret)
+	ret = dcfg->ops->start(rproc);
+	if (ret) {
 		dev_err(dev, "Failed to enable remote core!\n");
-	else if (priv->flags & WAIT_FW_READY)
+		return ret;
+	}
+
+	if (priv->flags & WAIT_FW_READY)
 		return imx_dsp_rproc_ready(rproc);
 
-	return ret;
+	return 0;
 }
 
 static int imx_dsp_rproc_mmio_stop(struct rproc *rproc)
@@ -431,20 +430,18 @@ static int imx_dsp_rproc_stop(struct rproc *rproc)
 		return 0;
 	}
 
-	if (dcfg->ops && dcfg->ops->stop) {
-		ret = dcfg->ops->stop(rproc);
-		goto stop_ret;
-	}
-
-	return -EOPNOTSUPP;
+	if (!dcfg->ops || !dcfg->ops->stop)
+		return -EOPNOTSUPP;
 
-stop_ret:
-	if (ret)
+	ret = dcfg->ops->stop(rproc);
+	if (ret) {
 		dev_err(dev, "Failed to stop remote core\n");
-	else
-		priv->flags &= ~REMOTE_IS_READY;
+		return ret;
+	}
 
-	return ret;
+	priv->flags &= ~REMOTE_IS_READY;
+
+	return 0;
 }
 
 /**

-- 
2.37.1
Re: [PATCH v4 12/12] remoteproc: imx_dsp_rproc: simplify start/stop error handling
Posted by Frank Li 1 week, 5 days ago
On Wed, Nov 19, 2025 at 12:21:57PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Replace goto-based error handling with early return pattern in
> imx_dsp_rproc_{start,stop}() functions, and simplify if-else logic.
>
> No functional changes, only code structure improvements for better
> maintainability.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/remoteproc/imx_dsp_rproc.c | 39 ++++++++++++++++++--------------------
>  1 file changed, 18 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c
> index 6237e8db2eff759c2b7fcce5fb4a44e4ebaec8cf..1a1438823e7fc0a65ba15142abdd97e59692801c 100644
> --- a/drivers/remoteproc/imx_dsp_rproc.c
> +++ b/drivers/remoteproc/imx_dsp_rproc.c
> @@ -376,20 +376,19 @@ static int imx_dsp_rproc_start(struct rproc *rproc)
>  	struct device *dev = rproc->dev.parent;
>  	int ret;
>
> -	if (dcfg->ops && dcfg->ops->start) {
> -		ret = dcfg->ops->start(rproc);
> -		goto start_ret;
> -	}
> -
> -	return -EOPNOTSUPP;
> +	if (!dcfg->ops || !dcfg->ops->start)
> +		return -EOPNOTSUPP;
>
> -start_ret:
> -	if (ret)
> +	ret = dcfg->ops->start(rproc);
> +	if (ret) {
>  		dev_err(dev, "Failed to enable remote core!\n");
> -	else if (priv->flags & WAIT_FW_READY)
> +		return ret;
> +	}
> +
> +	if (priv->flags & WAIT_FW_READY)
>  		return imx_dsp_rproc_ready(rproc);
>
> -	return ret;
> +	return 0;
>  }
>
>  static int imx_dsp_rproc_mmio_stop(struct rproc *rproc)
> @@ -431,20 +430,18 @@ static int imx_dsp_rproc_stop(struct rproc *rproc)
>  		return 0;
>  	}
>
> -	if (dcfg->ops && dcfg->ops->stop) {
> -		ret = dcfg->ops->stop(rproc);
> -		goto stop_ret;
> -	}
> -
> -	return -EOPNOTSUPP;
> +	if (!dcfg->ops || !dcfg->ops->stop)
> +		return -EOPNOTSUPP;
>
> -stop_ret:
> -	if (ret)
> +	ret = dcfg->ops->stop(rproc);
> +	if (ret) {
>  		dev_err(dev, "Failed to stop remote core\n");
> -	else
> -		priv->flags &= ~REMOTE_IS_READY;
> +		return ret;
> +	}
>
> -	return ret;
> +	priv->flags &= ~REMOTE_IS_READY;
> +
> +	return 0;
>  }
>
>  /**
>
> --
> 2.37.1
>
Re: [PATCH v4 12/12] remoteproc: imx_dsp_rproc: simplify start/stop error handling
Posted by Daniel Baluta 1 week, 5 days ago
On Wed, Nov 19, 2025 at 6:27 AM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote:
>
> From: Peng Fan <peng.fan@nxp.com>
>
> Replace goto-based error handling with early return pattern in
> imx_dsp_rproc_{start,stop}() functions, and simplify if-else logic.
>
> No functional changes, only code structure improvements for better
> maintainability.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>