From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Subject: [PATCH] remoteproc: qcom: Fix error handling paths in order to avoid memory leaks Date: Wed, 15 Nov 2017 07:58:35 +0100 [thread overview] Message-ID: <20171115065835.14525-1-christophe.jaillet@wanadoo.fr> (raw) In case of error returned by 'q6v5_xfer_mem_ownership', we must free some resources before returning. In 'q6v5_mpss_init_image()', add a new label to undo a previous 'dma_alloc_attrs()'. In 'q6v5_mpss_load()', re-use the already existing error handling code to undo a previous 'request_firmware()', as already done in the other error handling paths of the function. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- We could certainly also propagate the error code returned by 'q6v5_xfer_mem_ownership()' instead of returning an unconditional -EAGAIN. Not sure of the potential impacts, so I've left it as-is. --- drivers/remoteproc/qcom_q6v5_pil.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_pil.c b/drivers/remoteproc/qcom_q6v5_pil.c index a019796c363a..8a3fa2bcc9f6 100644 --- a/drivers/remoteproc/qcom_q6v5_pil.c +++ b/drivers/remoteproc/qcom_q6v5_pil.c @@ -580,7 +580,8 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) if (ret) { dev_err(qproc->dev, "assigning Q6 access to metadata failed: %d\n", ret); - return -EAGAIN; + ret = -EAGAIN; + goto free_dma_attrs; } writel(phys, qproc->rmb_base + RMB_PMI_META_DATA_REG); @@ -599,6 +600,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) dev_warn(qproc->dev, "mdt buffer not reclaimed system may become unstable\n"); +free_dma_attrs: dma_free_attrs(qproc->dev, fw->size, ptr, phys, dma_attrs); return ret < 0 ? ret : 0; @@ -712,7 +714,8 @@ static int q6v5_mpss_load(struct q6v5 *qproc) if (ret) { dev_err(qproc->dev, "assigning Q6 access to mpss memory failed: %d\n", ret); - return -EAGAIN; + ret = -EAGAIN; + goto release_firmware; } boot_addr = relocate ? qproc->mpss_phys : min_addr; -- 2.14.1
WARNING: multiple messages have this Message-ID (diff)
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Subject: [PATCH] remoteproc: qcom: Fix error handling paths in order to avoid memory leaks Date: Wed, 15 Nov 2017 06:58:35 +0000 [thread overview] Message-ID: <20171115065835.14525-1-christophe.jaillet@wanadoo.fr> (raw) In case of error returned by 'q6v5_xfer_mem_ownership', we must free some resources before returning. In 'q6v5_mpss_init_image()', add a new label to undo a previous 'dma_alloc_attrs()'. In 'q6v5_mpss_load()', re-use the already existing error handling code to undo a previous 'request_firmware()', as already done in the other error handling paths of the function. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- We could certainly also propagate the error code returned by 'q6v5_xfer_mem_ownership()' instead of returning an unconditional -EAGAIN. Not sure of the potential impacts, so I've left it as-is. --- drivers/remoteproc/qcom_q6v5_pil.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_pil.c b/drivers/remoteproc/qcom_q6v5_pil.c index a019796c363a..8a3fa2bcc9f6 100644 --- a/drivers/remoteproc/qcom_q6v5_pil.c +++ b/drivers/remoteproc/qcom_q6v5_pil.c @@ -580,7 +580,8 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) if (ret) { dev_err(qproc->dev, "assigning Q6 access to metadata failed: %d\n", ret); - return -EAGAIN; + ret = -EAGAIN; + goto free_dma_attrs; } writel(phys, qproc->rmb_base + RMB_PMI_META_DATA_REG); @@ -599,6 +600,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) dev_warn(qproc->dev, "mdt buffer not reclaimed system may become unstable\n"); +free_dma_attrs: dma_free_attrs(qproc->dev, fw->size, ptr, phys, dma_attrs); return ret < 0 ? ret : 0; @@ -712,7 +714,8 @@ static int q6v5_mpss_load(struct q6v5 *qproc) if (ret) { dev_err(qproc->dev, "assigning Q6 access to mpss memory failed: %d\n", ret); - return -EAGAIN; + ret = -EAGAIN; + goto release_firmware; } boot_addr = relocate ? qproc->mpss_phys : min_addr; -- 2.14.1
next reply other threads:[~2017-11-15 6:58 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-11-15 6:58 Christophe JAILLET [this message] 2017-11-15 6:58 ` [PATCH] remoteproc: qcom: Fix error handling paths in order to avoid memory leaks Christophe JAILLET 2017-11-15 7:23 ` Bjorn Andersson 2017-11-15 7:23 ` Bjorn Andersson
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=20171115065835.14525-1-christophe.jaillet@wanadoo.fr \ --to=christophe.jaillet@wanadoo.fr \ --cc=bjorn.andersson@linaro.org \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-remoteproc@vger.kernel.org \ --cc=ohad@wizery.com \ /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: linkBe 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.