Linux-remoteproc Archive mirror
 help / color / mirror / Atom feed
From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	 Bjorn Andersson <andersson@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	 Sibi Sankar <sibis@codeaurora.org>,
	LKML <linux-kernel@vger.kernel.org>,
	 kernel-janitors@vger.kernel.org,
	Sibi Sankar <quic_sibis@quicinc.com>
Subject: Re: [PATCH] remoteproc: qcom: q6v5-mss: Use common error handling code in q6v5_mpss_load()
Date: Tue, 24 Sep 2024 22:49:41 +0300	[thread overview]
Message-ID: <tn4kxsouzpgimregroywzzvi3sjib7pvnpcnkcvccer5b7woxk@yzaqjwjxeyki> (raw)
In-Reply-To: <bea9842e-6910-4452-8f90-cb7482f3e76f@web.de>

On Tue, Sep 24, 2024 at 04:08:11PM GMT, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 24 Sep 2024 15:55:06 +0200
> 
> Add jump targets so that a bit of exception handling can be better reused
> at the end of this function implementation.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/remoteproc/qcom_q6v5_mss.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
> index 2a42215ce8e0..b398ae3083a1 100644
> --- a/drivers/remoteproc/qcom_q6v5_mss.c
> +++ b/drivers/remoteproc/qcom_q6v5_mss.c
> @@ -1451,9 +1451,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  				dev_err(qproc->dev,
>  					"failed to load segment %d from truncated file %s\n",
>  					i, fw_name);
> -				ret = -EINVAL;

Please keep error assignment where it is. It is much cleaner to read it
this way, rather than checking the error-handling basement.

> -				memunmap(ptr);
> -				goto release_firmware;
> +				goto e_inval_unmap;
>  			}
> 
>  			memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz);
> @@ -1464,18 +1462,15 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  							ptr, phdr->p_filesz);
>  			if (ret) {
>  				dev_err(qproc->dev, "failed to load %s\n", fw_name);
> -				memunmap(ptr);
> -				goto release_firmware;
> +				goto unmap_mem;
>  			}
> 
>  			if (seg_fw->size != phdr->p_filesz) {
>  				dev_err(qproc->dev,
>  					"failed to load segment %d from truncated file %s\n",
>  					i, fw_name);
> -				ret = -EINVAL;
>  				release_firmware(seg_fw);
> -				memunmap(ptr);
> -				goto release_firmware;
> +				goto e_inval_unmap;
>  			}
> 
>  			release_firmware(seg_fw);
> @@ -1528,6 +1523,12 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  	kfree(fw_name);
> 
>  	return ret < 0 ? ret : 0;
> +
> +e_inval_unmap:
> +	ret = -EINVAL;
> +unmap_mem:
> +	memunmap(ptr);
> +	goto release_firmware;

Ugh. No. ptr should be a variable that is declared inside the loop.
Calling memunmap outside of the for loop is incorrect. And goto just
complicates things by adding non-linearity.

>  }
> 
>  static void qcom_q6v5_dump_segment(struct rproc *rproc,
> --
> 2.46.1
> 

-- 
With best wishes
Dmitry

      reply	other threads:[~2024-09-24 19:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 14:08 [PATCH] remoteproc: qcom: q6v5-mss: Use common error handling code in q6v5_mpss_load() Markus Elfring
2024-09-24 19:49 ` Dmitry Baryshkov [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=tn4kxsouzpgimregroywzzvi3sjib7pvnpcnkcvccer5b7woxk@yzaqjwjxeyki \
    --to=dmitry.baryshkov@linaro.org \
    --cc=Markus.Elfring@web.de \
    --cc=andersson@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=quic_sibis@quicinc.com \
    --cc=sibis@codeaurora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).