From patchwork Wed Nov 15 06:58:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 10058871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 273116019D for ; Wed, 15 Nov 2017 06:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16AFE28F09 for ; Wed, 15 Nov 2017 06:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09C6229C30; Wed, 15 Nov 2017 06:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 552AF28F09 for ; Wed, 15 Nov 2017 06:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754333AbdKOG7j (ORCPT ); Wed, 15 Nov 2017 01:59:39 -0500 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:50150 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754305AbdKOG7j (ORCPT ); Wed, 15 Nov 2017 01:59:39 -0500 Received: from localhost.localdomain ([86.196.182.67]) by mwinf5d16 with ME id a6zZ1w0031TfVo6036zZv1; Wed, 15 Nov 2017 07:59:36 +0100 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 15 Nov 2017 07:59:36 +0100 X-ME-IP: 86.196.182.67 From: Christophe JAILLET 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 Subject: [PATCH] remoteproc: qcom: Fix error handling paths in order to avoid memory leaks Date: Wed, 15 Nov 2017 07:58:35 +0100 Message-Id: <20171115065835.14525-1-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.14.1 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;