From patchwork Mon Mar 18 20:47:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10858557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9F5A1669 for ; Mon, 18 Mar 2019 20:47:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A96C929481 for ; Mon, 18 Mar 2019 20:47:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D7D9285C8; Mon, 18 Mar 2019 20:47:55 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 341E628514 for ; Mon, 18 Mar 2019 20:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1an4Sjg/SIiCxnfp3vj13kbf8VYZ5czoxXW86mNBB8o=; b=BM4AhQpEPrl/R2 cNOKi6o9Kg5HYnbDqbKJYaXCpU1RANX2pyBHH2aXZ1h/MbIkGZQlghHphlApfYWW4y16RrmT3f9/I Ps9DrQa+M3SCUwgVSQtSMLvwnq/lJMPeLMgL3SwjtRnvc2fbnTx76JxKAg20YYrk8ETVpyb+5kQrM FMOVjY3OqD9VeOWV4vnokdNnreOFuA8HoKcFZJOojRj30GJ+vt1do2Hp8RMMYCcyZZcBcImAhukoQ 4aiai8y1DDULwJrIgKmQnEh6LFOc/32ch3e502eNAL9h5fW35qAa9Ku6ShkWwB9PpUrpUaO5kghIe wALRjZax+1pksuxkm6Ag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h5zAm-0000aO-KJ; Mon, 18 Mar 2019 20:47:52 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h5zAS-00005S-7W; Mon, 18 Mar 2019 20:47:33 +0000 Received: by mail-wr1-x443.google.com with SMTP id w2so18601937wrt.11; Mon, 18 Mar 2019 13:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0873ZLskCB6Lvg+syhxqGIBY5YOohbYE2wenaTl30+w=; b=QtGreQaPHla07Yp+mGiHlv3HE2rnqgE7Ji7JfX3ujMrf6GxlwfHLXUY1LhjBUhYAvW PjpAM9wdto38jH6IF6kpeqeLgFhcL4WdLR/hHzO8cAFqrC3oBAhyx1tVsZ06gYqIvxv3 EuvsJbAFtVbLoKKRsgwiJpTDsM7R4Ce5x52PrNmy2BmuIQvBy6piur162MyYCaR8rP9a NWkZ+/POi3kzOO/WlZpco6FqcwOJqnlgtA+BlW6YpJuJ11nV8z7wMNDARxG+EfL4s/K/ e+HStdIuNJYYL2tn0UXh8XYp0YQtemd6tkB291/MU2Ia3QzbKutQe+TH48+nc4CB2gXh lm4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0873ZLskCB6Lvg+syhxqGIBY5YOohbYE2wenaTl30+w=; b=I6omGPigVmgLEcOhtICQZq5Oy8qqRLPfK9vA+jNgHFErbbg27Apn6iGITrUaJusgW9 IEd8qAtCIPlxqRvxUSpSs7tP3Kb3mg36WLlNktZjC9G6FudE8VkjlAbtawS6NfOB8I0i RAGwN1JD8TLOI3Ea/Bk2nvRlASILXxayYpHJ0NMuvyQ7VyD+qK47LmUgW7GYISWWos14 qGcxOpTRfO/vvaH7jkJ5JGSXqsdwHGiEoo7rOItEIqB4EsHvtnC6W5m41wvB2KzBJyJe yq8kVbyJ/nbekNqVwwpvT7SSwz4i/YSrI2rkz6OaoftXQGynD0+EzyqiPDdDe1Htqv8H hLnQ== X-Gm-Message-State: APjAAAW97T8D39KATyqWGu3D7Y4WL2lMOMwDUFJopvsMelrJg+yEnLnh DBaYKOfugDGbRvMtvf0GSLEza+iC X-Google-Smtp-Source: APXvYqyg9XphgCbZpbnjd28jfUaYDrWSVUE7pZocWpFznrc+9Gl/E/JaIExeGJ7Ymx5XIxgcE0bOGQ== X-Received: by 2002:adf:84c6:: with SMTP id 64mr14357276wrg.246.1552942050247; Mon, 18 Mar 2019 13:47:30 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD7399900918378ACFECF051C.dip0.t-ipconnect.de. [2003:dc:d739:9900:9183:78ac:fecf:51c]) by smtp.googlemail.com with ESMTPSA id y12sm224849wma.44.2019.03.18.13.47.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 13:47:29 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-mtd@lists.infradead.org, bbrezillon@kernel.org, miquel.raynal@bootlin.com Subject: [PATCH v2 2/2] mtd: rawnand: meson: fix a potential memory leak in meson_nfc_read_buf Date: Mon, 18 Mar 2019 21:47:22 +0100 Message-Id: <20190318204722.9901-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318204722.9901-1-martin.blumenstingl@googlemail.com> References: <20190318204722.9901-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190318_134732_267865_52F4ED1B X-CRM114-Status: GOOD ( 11.68 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , richard@nod.at, liang.yang@amlogic.com, linux-kernel@vger.kernel.org, jianxin.pan@amlogic.com Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP meson_nfc_dma_buffer_setup() is called with the "info" buffer which is allocated a few lines before using kzalloc(). If meson_nfc_dma_buffer_setup() fails we need to free the allocated "info" buffer instead of only freeing it upon success. Fixes: 8fae856c53500a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller") Signed-off-by: Martin Blumenstingl Acked-by: Liang Yang Reviewed-by: Kevin Hilman --- drivers/mtd/nand/raw/meson_nand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index a1d8506b61c7..38db4fd61459 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -534,7 +534,7 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) ret = meson_nfc_dma_buffer_setup(nand, buf, len, info, PER_INFO_BYTE, DMA_FROM_DEVICE); if (ret) - return ret; + goto out; cmd = NFC_CMD_N2M | (len & GENMASK(5, 0)); writel(cmd, nfc->reg_base + NFC_REG_CMD); @@ -542,6 +542,8 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) meson_nfc_drain_cmd(nfc); meson_nfc_wait_cmd_finish(nfc, 1000); meson_nfc_dma_buffer_release(nand, len, PER_INFO_BYTE, DMA_FROM_DEVICE); + +out: kfree(info); return ret;