[{"id":1961085,"web_url":"http://patchwork.ozlabs.org/comment/1961085/","msgid":"<20180725174733.3870e52a@bbrezillon>","list_archive_url":null,"date":"2018-07-25T15:47:33","subject":"Re: [PATCH v5 08/17] mtd: rawnand: docg4: convert driver to\n\tnand_scan()","submitter":{"id":73370,"url":"http://patchwork.ozlabs.org/api/people/73370/","name":"Boris Brezillon","email":"boris.brezillon@bootlin.com"},"content":"On Wed, 25 Jul 2018 15:31:43 +0200\nMiquel Raynal <miquel.raynal@bootlin.com> wrote:\n\n> Two helpers have been added to the core to do all kind of controller\n> side configuration/initialization between the detection phase and the\n> final NAND scan. Implement these hooks so that we can convert the driver\n> to just use nand_scan() instead of the nand_scan_ident() +\n> nand_scan_tail() pair.\n> \n> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>\n> ---\n>  drivers/mtd/nand/raw/docg4.c | 70 ++++++++++++++++++++++++++++----------------\n>  1 file changed, 45 insertions(+), 25 deletions(-)\n> \n> diff --git a/drivers/mtd/nand/raw/docg4.c b/drivers/mtd/nand/raw/docg4.c\n> index 4dccdfba6140..b69a36842605 100644\n> --- a/drivers/mtd/nand/raw/docg4.c\n> +++ b/drivers/mtd/nand/raw/docg4.c\n> @@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd)\n>  \t * required within a nand driver because they are performed by the nand\n>  \t * infrastructure code as part of nand_scan().  In this case they need\n>  \t * to be initialized here because we skip call to nand_scan_ident() (the\n> -\t * first half of nand_scan()).  The call to nand_scan_ident() is skipped\n> -\t * because for this device the chip id is not read in the manner of a\n> -\t * standard nand device.  Unfortunately, nand_scan_ident() does other\n> -\t * things as well, such as call nand_set_defaults().\n> +\t * first half of nand_scan()).  The call to nand_scan_ident() could be\n> +\t * skipped because for this device the chip id is not read in the manner\n> +\t * of a standard nand device.\n>  \t */\n>  \n>  \tstruct nand_chip *nand = mtd_to_nand(mtd);\n> @@ -1315,6 +1314,40 @@ static int __init read_id_reg(struct mtd_info *mtd)\n>  \n>  static char const *part_probes[] = { \"cmdlinepart\", \"saftlpart\", NULL };\n>  \n> +static int docg4_attach_chip(struct nand_chip *chip)\n> +{\n> +\tstruct mtd_info *mtd = nand_to_mtd(chip);\n> +\tstruct docg4_priv *doc = (struct docg4_priv *)(chip + 1);\n> +\tint ret;\n> +\n> +\tinit_mtd_structs(mtd);\n> +\n> +\t/* Initialize kernel BCH algorithm */\n> +\tdoc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);\n> +\tif (!doc->bch)\n> +\t\treturn -EINVAL;\n> +\n> +\treset(mtd);\n> +\n> +\tret = read_id_reg(mtd);\n> +\tif (ret)\n> +\t\tfree_bch(doc->bch);\n> +\n> +\treturn ret;\n> +}\n> +\n> +static void docg4_detach_chip(struct nand_chip *chip)\n> +{\n> +\tstruct docg4_priv *doc = (struct docg4_priv *)(chip + 1);\n> +\n> +\tfree_bch(doc->bch);\n> +}\n> +\n> +static const struct nand_controller_ops docg4_controller_ops = {\n> +\t.attach_chip = docg4_attach_chip,\n> +\t.detach_chip = docg4_detach_chip,\n> +};\n> +\n>  static int __init probe_docg4(struct platform_device *pdev)\n>  {\n>  \tstruct mtd_info *mtd;\n> @@ -1350,28 +1383,17 @@ static int __init probe_docg4(struct platform_device *pdev)\n>  \tmtd->dev.parent = &pdev->dev;\n>  \tdoc->virtadr = virtadr;\n>  \tdoc->dev = dev;\n> -\n> -\tinit_mtd_structs(mtd);\n> -\n> -\t/* initialize kernel bch algorithm */\n> -\tdoc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);\n> -\tif (doc->bch == NULL) {\n> -\t\tretval = -EINVAL;\n> -\t\tgoto free_nand;\n> -\t}\n> -\n>  \tplatform_set_drvdata(pdev, doc);\n>  \n> -\treset(mtd);\n> -\tretval = read_id_reg(mtd);\n> -\tif (retval == -ENODEV) {\n> -\t\tdev_warn(dev, \"No diskonchip G4 device found.\\n\");\n> -\t\tgoto free_bch;\n> -\t}\n> -\n> -\tretval = nand_scan_tail(mtd);\n> +\t/*\n> +\t * Running nand_scan() with maxchips == 0 will skip nand_scan_ident(),\n> +\t * which is a specific operation with this driver and done in the\n> +\t * ->attach_chip callback.\n> +\t */\n> +\tnand->dummy_controller.ops = &docg4_controller_ops;\n> +\tretval = nand_scan(mtd, 0);\n>  \tif (retval)\n> -\t\tgoto free_bch;\n> +\t\tgoto free_nand;\n>  \n>  \tretval = read_factory_bbt(mtd);\n>  \tif (retval)\n> @@ -1387,8 +1409,6 @@ static int __init probe_docg4(struct platform_device *pdev)\n>  \n>  cleanup_nand:\n>  \tnand_cleanup(nand);\n> -free_bch:\n> -\tfree_bch(doc->bch);\n\nYou forgot to remove the free_bch() call in the remove path.\nWith this addressed\n\nReviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>\n\n>  free_nand:\n>  \tkfree(nand);\n>  unmap:","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=\"tT8Ltx2b\"; \n\tdkim-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 41bKPc3ScJz9s1x\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 26 Jul 2018 01:48:04 +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 1fiM19-0008DR-Sq; Wed, 25 Jul 2018 15:47:59 +0000","from mail.bootlin.com ([62.4.15.54])\n\tby bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))\n\tid 1fiM15-0008CD-0Z\n\tfor linux-mtd@lists.infradead.org; Wed, 25 Jul 2018 15:47:58 +0000","by mail.bootlin.com (Postfix, from userid 110)\n\tid 78744207AB; Wed, 25 Jul 2018 17:47:43 +0200 (CEST)","from bbrezillon (AAubervilliers-681-1-78-122.w90-88.abo.wanadoo.fr\n\t[90.88.20.122])\n\tby mail.bootlin.com (Postfix) with ESMTPSA id 152472073D;\n\tWed, 25 Jul 2018 17:47:33 +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:Cc:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=bh13AkMePkQXJbTS4WM+XAA0rOJNnyVfbZOyGBmnFAg=;\n\tb=tT8Ltx2bvFYOsI\n\tz82v40z1srLOkdmbAjlBQicFta2oWg8lYWA6RteZ2Q7jDVqQ4oC+1lkAMkKlDhNsF3n28kCAp9Eg1\n\ttsHEn7Z/0tVxq0SAN7+R9F/4sQKQ4ZvtHMYNWq1FK6nAPjGOz/rZNhoC3NYXxK7XnsSMu9ZD0hHg1\n\tAZ4EHi6YKox0/QHSHKraeVCSYvxz06FZsBpbJ3ExKbzGU4zCZ+OtqMIDk3zP5FITZch25khm87uzk\n\tlOzhG8qUY2V5UvAP6g0KpdWC+/aZlvrqMJIwgybUb4HjX/FuioRhFNsnXPMV6wn48TEl+wa+N6qHy\n\tFxBFCNbTJb5idjk2e+rA==;","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","Date":"Wed, 25 Jul 2018 17:47:33 +0200","From":"Boris Brezillon <boris.brezillon@bootlin.com>","To":"Miquel Raynal <miquel.raynal@bootlin.com>, Wenyou Yang\n\t<wenyou.yang@microchip.com>, Josh Wu <rainyfeeling@outlook.com>, Stefan\n\tAgner <stefan@agner.ch>, Lucas Stach <dev@lynxeye.de>","Subject":"Re: [PATCH v5 08/17] mtd: rawnand: docg4: convert driver to\n\tnand_scan()","Message-ID":"<20180725174733.3870e52a@bbrezillon>","In-Reply-To":"<20180725133152.30898-9-miquel.raynal@bootlin.com>","References":"<20180725133152.30898-1-miquel.raynal@bootlin.com>\n\t<20180725133152.30898-9-miquel.raynal@bootlin.com>","X-Mailer":"Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu)","MIME-Version":"1.0","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20180725_084756_545025_EC562EA7 ","X-CRM114-Status":"GOOD (  26.55  )","X-Spam-Score":"-0.0 (/)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.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":"Richard Weinberger <richard@nod.at>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>, linux-mtd@lists.infradead.org, \n\tMarek Vasut <marek.vasut@gmail.com>","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"}}]