Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp176652rwo; Fri, 21 Jul 2023 10:06:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEtBoqTMOg4JppG6mHmAbvdjkCmGq/qrI22gmkhqpTceVyK5QmBDLKR0Eg39GssGsM7tvTB X-Received: by 2002:a05:6a20:1451:b0:132:e62d:c53b with SMTP id a17-20020a056a20145100b00132e62dc53bmr3007140pzi.44.1689959213242; Fri, 21 Jul 2023 10:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689959213; cv=none; d=google.com; s=arc-20160816; b=sxoxei58MeYxyGRPWSr/s3LVY9qEsiq2fKWjx/OiReV1n1TYpi2GYyHX0yQ4Rtz+7U vGlXw5Z+wrQ3ixY1qU3D3eBCRjHI8sXYOB4S233NQ9XO0vD6mV/X3Qi1mHMq4S46ftP8 Eowi3SV4Jz/KjwawBdPs8ozyXrFYrAyxOejIZwVBn8rNqITZEI+W+s+H9W0EtFfezmOY jm7ea0jzVeAx6RGyYSc7RyzrB6rrMMU0j5TC+bq1PlxaX79GQaZdpiZ/I/0fREIzem6S R2eqVyNqCb9z28/lgDXQ+NXi2qdMrFQXsgz6VsVE/Y9Ie+tiJkd7PkL94fiNgc2/lUsR I84Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=DZR2yM8Kua7Tzu9sFnzBBA/z4UTPOww6KUQXhNEX3rA=; fh=thJwGOIztJkBzixU3MCKh5ZXDkYcRa6EV7s504ufYIw=; b=UaIbwubhl34xA64U/KHig7TYGWZf00KzEK9ZX2+JUepYL3MljSaIIBBDjPC3r8SWLC wD1p5GGaWO5jhgFV64K8OB4oUEafURQ0zmq5JspFLX/ptw4/5wb4Fd4w+/Q1SGnvbr6P oV5HQj89RNkoyJ5v73MfI0Jbwa+mT68lqUYf7srjfJ5lyyzsyt0UdPdttQDHYAnrqkyA WUQi492ZZ41eyJxxxhRK2F6KyzTrFNj2ezwZNDK7xbOwz0dh5vYB9wg/BY3nj5AiNz3v 0LY3tvQAU+qj+07wE+6xdYEuiNtOjBXDblS349ffbtr3lihHZXBkCFdwUAQnjIJ27eRR lmOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a056a000a1500b006866be8eed2si579221pfh.137.2023.07.21.10.06.37; Fri, 21 Jul 2023 10:06:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232905AbjGUQbO (ORCPT + 99 others); Fri, 21 Jul 2023 12:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjGUQav (ORCPT ); Fri, 21 Jul 2023 12:30:51 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF1D4697; Fri, 21 Jul 2023 09:28:58 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="346665433" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="346665433" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 09:27:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="1055606811" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="1055606811" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga005.fm.intel.com with ESMTP; 21 Jul 2023 09:27:41 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qMsyf-00CQg1-0P; Fri, 21 Jul 2023 19:27:37 +0300 Date: Fri, 21 Jul 2023 19:27:36 +0300 From: Andy Shevchenko To: nikita.shubin@maquefel.me Cc: Hartley Sweeten , Lennert Buytenhek , Alexander Sverdlin , Russell King , Lukasz Majewski , Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Turquette , Stephen Boyd , Daniel Lezcano , Thomas Gleixner , Alessandro Zummo , Alexandre Belloni , Wim Van Sebroeck , Guenter Roeck , Sebastian Reichel , Thierry Reding , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Mark Brown , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vinod Koul , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Damien Le Moal , Sergey Shtylyov , Dmitry Torokhov , Arnd Bergmann , Olof Johansson , soc@kernel.org, Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Michael Peters , Kris Bahnsen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-pm@vger.kernel.org, linux-pwm@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, dmaengine@vger.kernel.org, linux-mtd@lists.infradead.org, linux-ide@vger.kernel.org, linux-input@vger.kernel.org, alsa-devel@alsa-project.org Subject: Re: [PATCH v3 24/42] mtd: nand: add support for ts72xx Message-ID: References: <20230605-ep93xx-v3-0-3d63a5f1103e@maquefel.me> <20230605-ep93xx-v3-24-3d63a5f1103e@maquefel.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230605-ep93xx-v3-24-3d63a5f1103e@maquefel.me> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 20, 2023 at 02:29:24PM +0300, Nikita Shubin via B4 Relay wrote: > From: Nikita Shubin > > Technologic Systems has it's own nand controller implementation in CPLD. ... + bits.h > +#include > +#include > +#include > +#include > +#include ... > +static int ts72xx_nand_attach_chip(struct nand_chip *chip) > +{ > + switch (chip->ecc.engine_type) { > + case NAND_ECC_ENGINE_TYPE_SOFT: > + if (chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN) > + chip->ecc.algo = NAND_ECC_ALGO_HAMMING; > + break; > + case NAND_ECC_ENGINE_TYPE_ON_HOST: > + return -EINVAL; > + default: > + break; Here it will return 0, is it a problem? > + } > + > + return 0; > +} ... > +static int ts72xx_nand_probe(struct platform_device *pdev) > +{ > + struct ts72xx_nand_data *data; > + struct device_node *child; > + struct mtd_info *mtd; > + int err; > + /* Allocate memory for the device structure (and zero it) */ Useless comment. > + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); > + if (!data) > + return -ENOMEM; > + > + data->controller.ops = &ts72xx_nand_ops; > + nand_controller_init(&data->controller); > + data->chip.controller = &data->controller; > + > + data->io_base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(data->io_base)) > + return PTR_ERR(data->io_base); > + > + child = of_get_next_child(pdev->dev.of_node, NULL); Why not using device property API from day 1? fwnode_get_next_child_node() > + if (!child) > + return dev_err_probe(&pdev->dev, -ENXIO, > + "ts72xx controller node should have exactly one child\n"); From now on you leak the reference count in error path. > + nand_set_flash_node(&data->chip, child); > + mtd = nand_to_mtd(&data->chip); > + mtd->dev.parent = &pdev->dev; > + > + data->chip.legacy.IO_ADDR_R = data->io_base; > + data->chip.legacy.IO_ADDR_W = data->io_base; > + data->chip.legacy.cmd_ctrl = ts72xx_nand_hwcontrol; > + data->chip.legacy.dev_ready = ts72xx_nand_device_ready; > + > + platform_set_drvdata(pdev, data); > + > + /* > + * This driver assumes that the default ECC engine should be TYPE_SOFT. > + * Set ->engine_type before registering the NAND devices in order to > + * provide a driver specific default value. > + */ > + data->chip.ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; > + > + /* Scan to find existence of the device */ > + err = nand_scan(&data->chip, 1); > + if (err) > + return err; > + > + err = mtd_device_parse_register(mtd, NULL, NULL, NULL, 0); > + if (err) { > + nand_cleanup(&data->chip); > + return err; > + } > + > + return 0; These 4 lines can be simply return err; but see above. > +} ... > +static void ts72xx_nand_remove(struct platform_device *pdev) > +{ > + struct ts72xx_nand_data *data = platform_get_drvdata(pdev); > + struct nand_chip *chip = &data->chip; > + int ret; > + > + ret = mtd_device_unregister(nand_to_mtd(chip)); > + WARN_ON(ret); Why?! Is it like this in other MTD drivers? > + nand_cleanup(chip); > +} -- With Best Regards, Andy Shevchenko