From patchwork Tue Dec 5 11:09:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 844691 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pLXHcye6"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yrfDS4mgGz9tB8 for ; Tue, 5 Dec 2017 22:10:32 +1100 (AEDT) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=twMWaHIxvweSpHVG31W+czRSH8w891+H7s+4gUiO11U=; b=pLXHcye6Z1ahfvfGH9r7rMX18/ lawV88cLSZ0B78YYEgb3iLJzzev1dc1yEuYbEiH6y1GiKifrETDqrZtz7GaomzfIdGHjUMUaQVEgZ 6wAYA/fY68LJdQ5I+p/ERUbPAD2GM2BYTLzqNP+kVuUyoLZc2putn1ADXCM+jIm0oJklxoCa0as7j g0GVucT6tRCrAp/k0zDxOfAjjf4g72lUjVwSYi+tDsdpuzcLzMo3DmCEFebbovF5tr8dGN7WrkxtH NTQ4T5aylijmVv7jNHpcRNZaegUihIfE0prkwhaybc5tOBHiJroH7ikLG0CgofwKOE4TzUeewjtXh k+0Apa7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMB7H-0002DR-0r; Tue, 05 Dec 2017 11:10:23 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMB6y-0000kG-Ib for linux-mtd@lists.infradead.org; Tue, 05 Dec 2017 11:10:11 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 89DCB20388; Tue, 5 Dec 2017 12:09:42 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 4857B2037C; Tue, 5 Dec 2017 12:09:32 +0100 (CET) From: Boris Brezillon To: Boris Brezillon , Richard Weinberger , linux-mtd@lists.infradead.org Subject: [PATCH 2/2] mtd: nand: Only allocate ecc->{calc, code}_buf when actually needed Date: Tue, 5 Dec 2017 12:09:29 +0100 Message-Id: <20171205110929.6820-2-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171205110929.6820-1-boris.brezillon@free-electrons.com> References: <20171205110929.6820-1-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_031004_779673_3F23E051 X-CRM114-Status: GOOD ( 12.80 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Masahiro Yamada , Marek Vasut , Brian Norris , David Woodhouse , Cyrille Pitchen MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The only users of the ecc->{calc,code}_buf buffers are NAND controller drivers implementing ecc->calculate() and/or ecc->correct(). Since the ->oobsize can be non-negligle, especially on modern NAND devices, we'd better allocate it only when it is actually required. Make ecc->{calc,code}_buf allocation dependent on the presence of ecc->calculate() or ecc->correct(). Signed-off-by: Boris Brezillon Reviewed-by: Masahiro Yamada --- drivers/mtd/nand/nand_base.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 71e70c4964f3..e6873d10c574 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -5318,21 +5318,9 @@ int nand_scan_tail(struct mtd_info *mtd) return -EINVAL; } - ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL); - if (!ecc->calc_buf) - return -ENOMEM; - - ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL); - if (!ecc->code_buf) { - ret = -ENOMEM; - goto err_free_buf; - } - chip->data_buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); - if (!chip->data_buf) { - ret = -ENOMEM; - goto err_free_buf; - } + if (!chip->data_buf) + return -ENOMEM; /* * FIXME: some NAND manufacturer drivers expect the first die to be @@ -5495,6 +5483,15 @@ int nand_scan_tail(struct mtd_info *mtd) goto err_nand_manuf_cleanup; } + if (ecc->correct || ecc->calculate) { + ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL); + ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!ecc->calc_buf || !ecc->code_buf) { + ret = -ENOMEM; + goto err_nand_manuf_cleanup; + } + } + /* For many systems, the standard OOB write also works for raw */ if (!ecc->read_oob_raw) ecc->read_oob_raw = ecc->read_oob;