From patchwork Mon Mar 18 20:47:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10858555 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 4822A1575 for ; Mon, 18 Mar 2019 20:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26997287C0 for ; Mon, 18 Mar 2019 20:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A3AE2948C; Mon, 18 Mar 2019 20:47:42 +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 C3A8429481 for ; Mon, 18 Mar 2019 20:47:41 +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=NDp+IE5USwzBloR2XmXk1SNkKw0n1s5DT3JTOujCMiU=; b=E/SwWAV60SBg/P c1NApGccrlAxIrbiyBguA7uAspiE3WaOHyVkJXEeOhCZab8YHQmOKF4sTN98w7mJtrLjPfyxrNN6o u+nXa3pfWYLA+pE3dQtawc4qUzfQcqbGbQI5oKchXIHKID60CSetezR4Rfs+5pk6PVuMb80nVj6RR +b8/lVS3r5pPZYnAQK1Srtt+POmaZ6byGN8txNShsLACQYIdsYxfnFaUjjhT+hjeUJPp1EUDVKLgG fwgbGXdT+yWl2Z0gkWSPpsgcSxpt5LXW86J+jWOtlp8GrifR67OpQxwJJrJMSbi5P0eBS++5ZRUJM wZm9xcfm85iq8VL4waMA==; 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 1h5zAa-0000I1-Q7; Mon, 18 Mar 2019 20:47:40 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h5zAQ-000050-QE; Mon, 18 Mar 2019 20:47:31 +0000 Received: by mail-wm1-x343.google.com with SMTP id t124so14249683wma.4; Mon, 18 Mar 2019 13:47:30 -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=gTFecInQYP9wwQj812Skvi7oL3bq5LWKLMuFYZPP1Fw=; b=aWzaZ5KD2byT04qun1TNGBXfcx+En48cCP1ycdeUE8xD7chQW38vxt7jkkE/Hs78O9 FIpluGwpjRIZDbTOrh+0dzzkBI/mYBwzt3VXj1bV+o6+RANctLylQwmqv74UHzYp7Xa7 Zw5v0OWk8pPOW7oTR+Hgp/EQxj5MKmHjFostPcrdNrbyLUBbB6psN1T33l2dHEk5FfcU liIhRDgS0fRwJ7QdnxAdD8VOR+F/GOGYgLKRykWRDRCsjbyHgcI4hhqjamNbclw6wn7q EuS/w8Wh0LS/xOfxOdwGxlv1Ph8fpX6I6d0mcCOL+GUKe/ihjtYFzbM3r4CU9X+Kp87C zJUw== 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=gTFecInQYP9wwQj812Skvi7oL3bq5LWKLMuFYZPP1Fw=; b=CWY6+7scrY5BrkVxfzN8THyPDePEqKF2R+dwe8yd23YS0CviY27XtW6CMXrdlX3wZc 6cneFWSDxeNL/VmgfXtWj4GVa4AnCi0pBnoKl02afrPh8FsU+UClCA4KJ9PZpsTQtjjD nJUYbzmKuKZ20viZIOxflwEu5ffi/VTo/eOTNeuBy18mDvhBYNXwx5ypkN5cRLyYSW8S P4qDlQQ3Cg1Fm0iKiVvBionVJkc2vduNA1yhJ2q9LSlQF4isG+t7K3C/UeyL+sgrZEi9 LcGnAu0d6H8w2EKEE1vJshGFKzyvnKiQSy/pAdMoGa6cFmidxvlQLCVJkSxJ8OKnn1lR 7+oA== X-Gm-Message-State: APjAAAVRRF+SBgSZJ6FXpgNoyQhYHl6z/24uz/zhXc9GOLgurDkM763A zGNGrpMFrTNeeRJTPRyp1Pu2SRka X-Google-Smtp-Source: APXvYqzOc9VNDbIX90H22bol5C6f4c1+BmYF1lTwu47Lth9itBXQhxsE2FeL557FDL+RUmR2PEqSCg== X-Received: by 2002:a1c:7c0c:: with SMTP id x12mr627498wmc.38.1552942048819; Mon, 18 Mar 2019 13:47:28 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 13:47:28 -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 1/2] mtd: rawnand: meson: add missing ENOMEM check in meson_nfc_read_buf() Date: Mon, 18 Mar 2019 21:47:21 +0100 Message-Id: <20190318204722.9901-2-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_134730_851849_9EA81FFD X-CRM114-Status: GOOD ( 10.78 ) 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 kzalloc() can return NULL if memory could not be allocated. Check the return value of the kzalloc() call in meson_nfc_read_buf() to make it consistent with other memory allocations within the meson_nand driver. 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 3e8aa71407b5..a1d8506b61c7 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -528,6 +528,9 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) u8 *info; info = kzalloc(PER_INFO_BYTE, GFP_KERNEL); + if (!info) + return -ENOMEM; + ret = meson_nfc_dma_buffer_setup(nand, buf, len, info, PER_INFO_BYTE, DMA_FROM_DEVICE); if (ret) 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;