From patchwork Fri Mar 2 17:03:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 880674 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=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uZuevg21"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="m6I4vo7S"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 3ztGgk5Xzgz9s3Z for ; Sat, 3 Mar 2018 04:36:34 +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=aYBkAfu45d0Ez1qNmVaHAhKIJKvyRZW0MGZ6k+9n764=; b=uZuevg21ZdlE8YHeJya+NJUUqD +GAiKpWLyffcPEQ7CGHmtVZ2u9wQkUTdfymBlEKoyOHF1u0UzVLUaEfAn/EyFKoBQFW4i5IZXdTiF bEgmly6GZkBZp5aLnG+91LPrtM2VRlFkLep0IIbTHkOUqxaw4iCw7X6SDfpbzqMR3YZFZO+ERy6jM 4ZTZv0loiyBOggKHTAc+oHxJNHaGu+QUFE0/F6ISMRyKUlcHXqR0RchKYrEbt+AyX3Fuqon7BQSQY /Btv7PEJWxillg+NixC886GBvTx+2tTPNDK2mSX7upVo/cOynSnL0F9QqQfKxhoEHrmmCnXOhv++U YAd3Z0GQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erobc-0006Nw-4G; Fri, 02 Mar 2018 17:36:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eroA5-0005sL-76; Fri, 02 Mar 2018 17:08:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HaK/kuuu75/nrNppmERODY33ISYf/NASY9ZSZ7fM2hQ=; b=m6I4vo7S96AtWDJAm4NDWMVkU x3cyKFkLKIjrYxjceGgKnqQ2oSvnST4ONHlROP2jLiazwY+IGKwmpTLiZJgx7+fIUK4jw9UuHOdXs xK+ZcVxnv6fyXddsYxZSrCt6oANQ/y57Y/kiKUiBOxRH6qTE9e/prIV/V0Jmf4Ig2tWWsnPzfraeL RHb8uanSTk8g3xjAPHmcJGXmsk0B3nAwRRLymCBKCtH0ievHgABofQz1SOiJmPtseyptQ3lwAaeG7 sr5HVQ8aDvOhyHp4hfYPHi6KCSlGAQ5LK+KTZOkWZwW6eh4yubBHrPjpNXmgvSFRFgosHvAFLxTWw XslFvNRqw==; Received: from mail.bootlin.com ([62.4.15.54]) by casper.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ero7E-0005ra-G0; Fri, 02 Mar 2018 17:05:06 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 69B2E20A03; Fri, 2 Mar 2018 18:04:47 +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 (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id 812C720379; Fri, 2 Mar 2018 18:04:46 +0100 (CET) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , Josh Wu , Kamal Dasu , Harvey Hunt , Stefan Agner Subject: [PATCH 51/52] mtd: rawnand: do not export nand_scan_[ident|tail]() anymore Date: Fri, 2 Mar 2018 18:03:59 +0100 Message-Id: <20180302170400.6712-52-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180302170400.6712-1-miquel.raynal@bootlin.com> References: <20180302170400.6712-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180302_170504_628137_BC9E8FF6 X-CRM114-Status: GOOD ( 25.57 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) 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: linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Miquel Raynal MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Both nand_scan_ident() and nand_scan_tail() helpers used to be called directly from controller drivers that needed to tweak some ECC-related parameters before nand_scan_tail(). This separation prevented dynamic allocations during the phase of NAND identification, which was inconvenient. All controller drivers have been moved to use nand_scan(), in conjunction with the chip->ecc.[attach|detach]_chip() hooks that actually do the required tweaking sequence between both ident/tail calls, allowing programmers to use dynamic allocation as they need all across the scanning sequence. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 54 ++++++++++++++++++++++++++++++++-------- include/linux/mtd/rawnand.h | 12 +++------ 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 0d850dbf843d..82d52112907f 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5100,6 +5100,7 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); struct nand_onfi_params *p; + char *model; char id[4]; int i, ret, val; @@ -5159,7 +5160,14 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) sanitize_string(p->manufacturer, sizeof(p->manufacturer)); sanitize_string(p->model, sizeof(p->model)); - memcpy(chip->parameters.model, p->model, sizeof(p->model)); + model = kzalloc(sizeof(p->model), GFP_KERNEL); + if (!model) { + ret = -ENOMEM; + goto free_onfi_param_page; + } + + memcpy(model, p->model, sizeof(p->model)); + chip->parameters.model = model; if (!mtd->name) mtd->name = chip->parameters.model; @@ -5240,6 +5248,7 @@ static int nand_flash_detect_jedec(struct nand_chip *chip) struct mtd_info *mtd = nand_to_mtd(chip); struct nand_jedec_params *p; struct jedec_ecc_info *ecc; + char *model; char id[5]; int i, val, ret; @@ -5290,7 +5299,14 @@ static int nand_flash_detect_jedec(struct nand_chip *chip) sanitize_string(p->manufacturer, sizeof(p->manufacturer)); sanitize_string(p->model, sizeof(p->model)); - memcpy(chip->parameters.model, p->model, sizeof(p->model)); + model = kzalloc(sizeof(p->model), GFP_KERNEL); + if (!p) { + ret = -ENOMEM; + goto free_jedec_param_page; + } + + memcpy(model, p->model, sizeof(p->model)); + chip->parameters.model = model; if (!mtd->name) mtd->name = chip->parameters.model; @@ -5858,7 +5874,7 @@ static int nand_dt_init(struct nand_chip *chip) } /** - * nand_scan_ident - [NAND Interface] Scan for the NAND device + * nand_scan_ident - Scan for the NAND device * @mtd: MTD device structure * @maxchips: number of chips to scan for * @table: alternative NAND ID table @@ -5866,9 +5882,13 @@ static int nand_dt_init(struct nand_chip *chip) * This is the first phase of the normal nand_scan() function. It reads the * flash ID and sets up MTD fields accordingly. * + * This helper used to be called directly from controller drivers that needed + * to tweak some ECC-related parameters before nand_scan_tail(). This separation + * prevented dynamic allocations during this phase which was unconvenient and + * as been banned for the benefit of the ->init_ecc()/cleanup_ecc() hooks. */ -int nand_scan_ident(struct mtd_info *mtd, int maxchips, - struct nand_flash_dev *table) +static int nand_scan_ident(struct mtd_info *mtd, int maxchips, + struct nand_flash_dev *table) { int i, nand_maf_id, nand_dev_id; struct nand_chip *chip = mtd_to_nand(mtd); @@ -5942,7 +5962,11 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, return 0; } -EXPORT_SYMBOL(nand_scan_ident); + +static void nand_scan_ident_cleanup(struct nand_chip *chip) +{ + kfree(chip->parameters.model); +} static int nand_set_ecc_soft_ops(struct mtd_info *mtd) { @@ -6295,14 +6319,14 @@ static bool nand_ecc_strength_good(struct mtd_info *mtd) } /** - * nand_scan_tail - [NAND Interface] Scan for the NAND device + * nand_scan_tail - Scan for the NAND device * @mtd: MTD device structure * * This is the second phase of the normal nand_scan() function. It fills out * all the uninitialized function pointers with the defaults and scans for a * bad block table if appropriate. */ -int nand_scan_tail(struct mtd_info *mtd) +static int nand_scan_tail(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); struct nand_ecc_ctrl *ecc = &chip->ecc; @@ -6626,7 +6650,6 @@ int nand_scan_tail(struct mtd_info *mtd) return ret; } -EXPORT_SYMBOL(nand_scan_tail); /* * is_module_text_address() isn't exported, and it's mostly a pointless @@ -6661,12 +6684,20 @@ int nand_scan(struct mtd_info *mtd, int maxchips) if (chip->ecc.attach_chip) { ret = chip->ecc.attach_chip(chip); if (ret) - return ret; + goto cleanup_ident; } ret = nand_scan_tail(mtd); + if (ret) + goto detach_chip; + + return 0; + +detach_chip: if (ret && chip->ecc.detach_chip) chip->ecc.detach_chip(chip); +cleanup_ident: + nand_scan_ident_cleanup(chip); return ret; } @@ -6699,6 +6730,9 @@ void nand_cleanup(struct nand_chip *chip) /* Free controller specific allocations after chip identification */ if (chip->ecc.detach_chip) chip->ecc.detach_chip(chip); + + /* Free identification phase allocations */ + nand_scan_ident_cleanup(chip); } EXPORT_SYMBOL_GPL(nand_cleanup); diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 318c73a206fc..9e15256bef2b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -29,15 +29,11 @@ struct device_node; /* Scan and identify a NAND device */ int nand_scan(struct mtd_info *mtd, int max_chips); + /* - * Separate phases of nand_scan(), allowing board driver to intervene - * and override command or ECC setup according to flash type. + * Unregister the MTD device and free resources held by the NAND device, must be + * called on error after a successful nand_scan(). */ -int nand_scan_ident(struct mtd_info *mtd, int max_chips, - struct nand_flash_dev *table); -int nand_scan_tail(struct mtd_info *mtd); - -/* Unregister the MTD device and free resources held by the NAND device */ void nand_release(struct mtd_info *mtd); /* Internal helper for board drivers which need to override command function */ @@ -443,7 +439,7 @@ struct onfi_params { struct nand_parameters { /* Generic parameters */ - char model[100]; + const char *model; bool supports_set_get_features; DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER); DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);