{"id":949205,"url":"http://patchwork.ozlabs.org/api/1.2/patches/949205/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20180725133152.30898-17-miquel.raynal@bootlin.com/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/1.2/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20180725133152.30898-17-miquel.raynal@bootlin.com>","list_archive_url":null,"date":"2018-07-25T13:31:51","name":"[v5,16/17] mtd: rawnand: allocate model parameter dynamically","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9532f46303e1ff7f0bd51e0ed0d36b970128ab2b","submitter":{"id":73368,"url":"http://patchwork.ozlabs.org/api/1.2/people/73368/?format=json","name":"Miquel Raynal","email":"miquel.raynal@bootlin.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20180725133152.30898-17-miquel.raynal@bootlin.com/mbox/","series":[{"id":57526,"url":"http://patchwork.ozlabs.org/api/1.2/series/57526/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=57526","date":"2018-07-25T13:31:36","name":"Allow dynamic allocations during NAND chip identification phase","version":5,"mbox":"http://patchwork.ozlabs.org/series/57526/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/949205/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/949205/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org\n\t(client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org;\n\tenvelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdmarc=none (p=none dis=none) header.from=bootlin.com","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"Mky5jomy\"; \n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=infradead.org header.i=@infradead.org\n\theader.b=\"UTvhwhQM\"; dkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[IPv6:2607:7c80:54:e::133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 41bGsV3dKfz9s4c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 25 Jul 2018 23:53:30 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))\n\tid 1fiKE4-0004hb-TP; Wed, 25 Jul 2018 13:53:12 +0000","from merlin.infradead.org ([2001:8b0:10b:1231::1])\n\tby bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat\n\tLinux)) id 1fiKE2-0004hN-QG\n\tfor linux-mtd@bombadil.infradead.org; Wed, 25 Jul 2018 13:53:10 +0000","from mail.bootlin.com ([62.4.15.54])\n\tby merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))\n\tid 1fiJuR-0001wF-Vh\n\tfor linux-mtd@lists.infradead.org; Wed, 25 Jul 2018 13:32:58 +0000","by mail.bootlin.com (Postfix, from userid 110)\n\tid 2BA112072F; Wed, 25 Jul 2018 15:32:27 +0200 (CEST)","from localhost.localdomain\n\t(AAubervilliers-681-1-78-122.w90-88.abo.wanadoo.fr [90.88.20.122])\n\tby mail.bootlin.com (Postfix) with ESMTPSA id AD10B20943;\n\tWed, 25 Jul 2018 15:32:00 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References:\n\tIn-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Owner;\n\tbh=0RA1s/Jy/brnXuArW2Xybu9iR49KBOj0WQJiWmMnK+E=;\n\tb=Mky5jomy1lHqzdN+hnaeY4/ZQC\n\tzKgMQTotAyzinS2fUnAJeXBx1otJWqKEq9Dbz8vgitIYMZo87Iw78FvjrZiDdDv04ljNeWYo7iCk3\n\tp9iTE2wbDMZnUXTmo5BceCiy7AVYxw11/v3gqDkcWIW5eQI4so0SGj2bO3Ph4co49Wc0JeOTNteXC\n\tQt78Wzme9KWE+A2nR4dq0xUO1ZSsg3/CSfNjv3SffRBw+lp1RXchXdEYj/4aGU2l/KCpYxh6HTr30\n\tU+Ef1d1LQLTsZifu4gXdxNNrcRpJdhHjFVHojJ3cxp1RX6v1CzMo2pKFcZb2gG/CghaN6iP5WK1b9\n\tVE30numA==;","v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=merlin.20170209;\n\th=References:In-Reply-To:Message-Id:Date:\n\tSubject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type:\n\tContent-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:\n\tResent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:\n\tList-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;\n\tbh=LFk4fNRXPgvifkErZ3Z6H7lntU5ZaUs5KzvsJqQgsHc=;\n\tb=UTvhwhQMQGmjDW74A35uussWg\n\tO32kIb/EID1jkUS+dR4qoBiOBTs09Mqut//zDZwYxGcvxplbxG914P95fzeJ0sB6DvQueB9+EDgnZ\n\tB7NQfAiJ3FDfzlATZPh1fnCEV4v7TyPsF40Kt0Cn6h41z6AeivLInymj33Frif345nuFUFKd/4rjn\n\tK/98cxkpv3jB4trIZX8SnA5nxGTpvQyBy0c/WdPUoyBcAD0uJviglpmVV9gwfI4ISq/Jjn9adkPB5\n\thXP4zz4cOe/8KjyfjQLmQXM2qFMdM2urXfH9XTa2Dl5jGuT7JVo0nQQ3Z7yCErjigcwlJBdD0gPYM\n\tx7U1V5zMg==;"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com","X-Spam-Level":"","X-Spam-Status":"No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT,\n\tURIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0","From":"Miquel Raynal <miquel.raynal@bootlin.com>","To":"Boris Brezillon <boris.brezillon@bootlin.com>,\n\tRichard Weinberger <richard@nod.at>,\n\tDavid Woodhouse <dwmw2@infradead.org>, \n\tBrian Norris <computersforpeace@gmail.com>,\n\tMarek Vasut <marek.vasut@gmail.com>","Subject":"[PATCH v5 16/17] mtd: rawnand: allocate model parameter dynamically","Date":"Wed, 25 Jul 2018 15:31:51 +0200","Message-Id":"<20180725133152.30898-17-miquel.raynal@bootlin.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20180725133152.30898-1-miquel.raynal@bootlin.com>","References":"<20180725133152.30898-1-miquel.raynal@bootlin.com>","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20180725_093256_259293_58ED5172 ","X-CRM114-Status":"GOOD (  16.94  )","X-Spam-Score":"-0.0 (/)","X-Spam-Report":"SpamAssassin version 3.4.1 on merlin.infradead.org summary:\n\tContent analysis details:   (-0.0 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,\n\tno trust [62.4.15.54 listed in list.dnswl.org]\n\t-0.0 SPF_PASS               SPF: sender matches SPF record","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Cc":"Lucas Stach <dev@lynxeye.de>, Wenyou Yang <wenyou.yang@microchip.com>,\n\tJosh Wu <rainyfeeling@outlook.com>, Stefan Agner <stefan@agner.ch>,\n\tlinux-mtd@lists.infradead.org, Miquel Raynal <miquel.raynal@bootlin.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"Thanks to the migration of all drivers to use nand_scan() and the\nrelated nand_controller_ops, we can now allocate data during the\ndetection phase. Let's do it first for the NAND model parameter which\nis allocated in nand_detect().\n\nSigned-off-by: Miquel Raynal <miquel.raynal@bootlin.com>\nReviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>\n---\n drivers/mtd/nand/raw/nand_base.c | 52 +++++++++++++++++++++++++++++++---------\n include/linux/mtd/rawnand.h      |  2 +-\n 2 files changed, 42 insertions(+), 12 deletions(-)","diff":"diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c\nindex 34ea44f90fd8..00e80781124a 100644\n--- a/drivers/mtd/nand/raw/nand_base.c\n+++ b/drivers/mtd/nand/raw/nand_base.c\n@@ -5225,8 +5225,11 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)\n \n \tsanitize_string(p->manufacturer, sizeof(p->manufacturer));\n \tsanitize_string(p->model, sizeof(p->model));\n-\tstrncpy(chip->parameters.model, p->model,\n-\t\tsizeof(chip->parameters.model) - 1);\n+\tchip->parameters.model = kstrdup(p->model, GFP_KERNEL);\n+\tif (!chip->parameters.model) {\n+\t\tret = -ENOMEM;\n+\t\tgoto free_onfi_param_page;\n+\t}\n \n \tmtd->writesize = le32_to_cpu(p->byte_per_page);\n \n@@ -5356,8 +5359,11 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)\n \n \tsanitize_string(p->manufacturer, sizeof(p->manufacturer));\n \tsanitize_string(p->model, sizeof(p->model));\n-\tstrncpy(chip->parameters.model, p->model,\n-\t\tsizeof(chip->parameters.model) - 1);\n+\tchip->parameters.model = kstrdup(p->model, GFP_KERNEL);\n+\tif (!chip->parameters.model) {\n+\t\tret = -ENOMEM;\n+\t\tgoto free_jedec_param_page;\n+\t}\n \n \tmtd->writesize = le32_to_cpu(p->byte_per_page);\n \n@@ -5546,8 +5552,9 @@ static bool find_full_id_nand(struct nand_chip *chip,\n \t\tchip->onfi_timing_mode_default =\n \t\t\t\t\ttype->onfi_timing_mode_default;\n \n-\t\tstrncpy(chip->parameters.model, type->name,\n-\t\t\tsizeof(chip->parameters.model) - 1);\n+\t\tchip->parameters.model = kstrdup(type->name, GFP_KERNEL);\n+\t\tif (!chip->parameters.model)\n+\t\t\treturn false;\n \n \t\treturn true;\n \t}\n@@ -5706,8 +5713,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)\n \tif (!type->name)\n \t\treturn -ENODEV;\n \n-\tstrncpy(chip->parameters.model, type->name,\n-\t\tsizeof(chip->parameters.model) - 1);\n+\tchip->parameters.model = kstrdup(type->name, GFP_KERNEL);\n+\tif (!chip->parameters.model)\n+\t\treturn -ENOMEM;\n \n \tchip->chipsize = (uint64_t)type->chipsize << 20;\n \n@@ -5737,7 +5745,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)\n \t\t\tmtd->name);\n \t\tpr_warn(\"bus width %d instead of %d bits\\n\", busw ? 16 : 8,\n \t\t\t(chip->options & NAND_BUSWIDTH_16) ? 16 : 8);\n-\t\treturn -EINVAL;\n+\t\tret = -EINVAL;\n+\n+\t\tgoto free_detect_allocation;\n \t}\n \n \tnand_decode_bbm_options(chip);\n@@ -5774,6 +5784,11 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)\n \t\t(int)(chip->chipsize >> 20), nand_is_slc(chip) ? \"SLC\" : \"MLC\",\n \t\tmtd->erasesize >> 10, mtd->writesize, mtd->oobsize);\n \treturn 0;\n+\n+free_detect_allocation:\n+\tkfree(chip->parameters.model);\n+\n+\treturn ret;\n }\n \n static const char * const nand_ecc_modes[] = {\n@@ -6013,6 +6028,11 @@ static int nand_scan_ident(struct mtd_info *mtd, int maxchips,\n \treturn 0;\n }\n \n+static void nand_scan_ident_cleanup(struct nand_chip *chip)\n+{\n+\tkfree(chip->parameters.model);\n+}\n+\n static int nand_set_ecc_soft_ops(struct mtd_info *mtd)\n {\n \tstruct nand_chip *chip = mtd_to_nand(mtd);\n@@ -6760,11 +6780,18 @@ int nand_scan_with_ids(struct mtd_info *mtd, int maxchips,\n \n \tret = nand_attach(chip);\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto cleanup_ident;\n \n \tret = nand_scan_tail(mtd);\n \tif (ret)\n-\t\tnand_detach(chip);\n+\t\tgoto detach_chip;\n+\n+\treturn 0;\n+\n+detach_chip:\n+\tnand_detach(chip);\n+cleanup_ident:\n+\tnand_scan_ident_cleanup(chip);\n \n \treturn ret;\n }\n@@ -6796,6 +6823,9 @@ void nand_cleanup(struct nand_chip *chip)\n \n \t/* Free controller specific allocations after chip identification */\n \tnand_detach(chip);\n+\n+\t/* Free identification phase allocations */\n+\tnand_scan_ident_cleanup(chip);\n }\n \n EXPORT_SYMBOL_GPL(nand_cleanup);\ndiff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h\nindex eaf000b09222..4848c00f3eda 100644\n--- a/include/linux/mtd/rawnand.h\n+++ b/include/linux/mtd/rawnand.h\n@@ -476,7 +476,7 @@ struct onfi_params {\n  */\n struct nand_parameters {\n \t/* Generic parameters */\n-\tchar model[100];\n+\tconst char *model;\n \tbool supports_set_get_features;\n \tDECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);\n \tDECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);\n","prefixes":["v5","16/17"]}