From patchwork Fri Dec 20 16:02:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 304135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 306EF2C00AD for ; Sat, 21 Dec 2013 03:04:09 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vu2YA-0008Oq-Gc; Fri, 20 Dec 2013 16:03:42 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vu2Y2-000830-68; Fri, 20 Dec 2013 16:03:34 +0000 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vu2Xe-0007wV-Fr; Fri, 20 Dec 2013 16:03:12 +0000 Received: by mail-pa0-f41.google.com with SMTP id lf10so2810702pab.14 for ; Fri, 20 Dec 2013 08:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MRGieKJDNfaQWH7F69hQ9cwEEpXDesufY5cvTByA7Wc=; b=KxJ01nLgD15TiaHyIpkZ4fDMzT4UL/oIkefLegpM3y7IPxpLeN1T96d1K0MckA9Byf B0rHQCzNj0PNkgPZiFNIfzvqUQR+FrT7+Em4f7QW8pd7rZRVhOcJCDy9dbbwOuKCD18H BvplqsnYzEpGvC/6M2tLjJUrNtSGV6XhNdZSjH5IRb6U/iz3kr/4XftkwX9WUzrq+CCv XkbVXs7IqpgqiUda0nzk/jNsphosTcvxANgGtBfkpa+UsutIlB4JN31qQKeGKxGv+RGw oAPM8v98s5uKr3tXnNGBhVM4WC5DxRs/+b4+Wy4dIBPsUQLIreugW25hI5Fc07llzwXY N9UA== X-Received: by 10.68.0.35 with SMTP id 3mr9451562pbb.52.1387555368026; Fri, 20 Dec 2013 08:02:48 -0800 (PST) Received: from localhost.localdomain ([139.226.110.218]) by mx.google.com with ESMTPSA id ka3sm15338993pbc.32.2013.12.20.08.02.44 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 20 Dec 2013 08:02:47 -0800 (PST) From: Huang Shijie To: dwmw2@infradead.org Subject: [PATCH 1/4] mtd: mxc-nand: kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE Date: Sat, 21 Dec 2013 00:02:27 +0800 Message-Id: <1387555350-989-2-git-send-email-shijie8@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1387555350-989-1-git-send-email-shijie8@gmail.com> References: <1387555350-989-1-git-send-email-shijie8@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131220_110310_800402_B5BB7ED0 X-CRM114-Status: GOOD ( 12.02 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (shijie8[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (shijie8[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: s.hauer@pengutronix.de, akinobu.mita@gmail.com, josh@joshtriplett.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Huang Shijie , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE by the following way: 1.) Before we call the nand_scan_ident, we allocate a temporary buffer whose size is PAGE_SIZE. 2.) After we finish the nand_scan_ident, we have already getten the page size and oob size. We will allocate the right buffer size again. Signed-off-by: Huang Shijie --- drivers/mtd/nand/mxc_nand.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 567a5e5..e9a4835 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -1399,12 +1399,15 @@ static int mxcnd_probe(struct platform_device *pdev) int err = 0; /* Allocate memory for MTD device structure and private data */ - host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host) + - NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE, GFP_KERNEL); + host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host), + GFP_KERNEL); if (!host) return -ENOMEM; - host->data_buf = (uint8_t *)(host + 1); + /* allocate a temporary buffer for the nand_scan_ident() */ + host->data_buf = devm_kzalloc(&pdev->dev, PAGE_SIZE, GFP_KERNEL); + if (!host->data_buf) + return -ENOMEM; host->dev = &pdev->dev; /* structures must be linked */ @@ -1532,6 +1535,15 @@ static int mxcnd_probe(struct platform_device *pdev) goto escan; } + /* allocate the right size buffer now */ + devm_kfree(&pdev->dev, (void *)host->data_buf); + host->data_buf = devm_kzalloc(&pdev->dev, mtd->writesize + mtd->oobsize, + GFP_KERNEL); + if (!host->data_buf) { + err = -ENOMEM; + goto escan; + } + /* Call preset again, with correct writesize this time */ host->devtype_data->preset(mtd);