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: 3389741 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C35489F37A for ; Fri, 20 Dec 2013 16:05:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3343206E0 for ; Fri, 20 Dec 2013 16:05:32 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71E2120692 for ; Fri, 20 Dec 2013 16:05:31 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vu2YY-0008WH-5l; Fri, 20 Dec 2013 16:04:08 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vu2YC-00083l-1b; Fri, 20 Dec 2013 16:03:44 +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 (-) 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-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);