Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6300302rwl; Thu, 29 Dec 2022 10:22:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUHChWy8+dvHCR6wRuGddplvPhDttptlJz11gs1H3YVSY7CxZR1j/XoZupUqAo7YW4spOv X-Received: by 2002:a50:fd87:0:b0:47f:1013:f3ac with SMTP id o7-20020a50fd87000000b0047f1013f3acmr26651466edt.4.1672338145147; Thu, 29 Dec 2022 10:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672338145; cv=none; d=google.com; s=arc-20160816; b=fTX5c1NWzrzZ57tdolYk93VGIonwZ5UPUaLgWv6wHDTwNczOQoSF4e6otvB3GAe0Jr 0OyLp3scPLnVmkRSY21u4lJawSdKVnmUEWFHtDrsyEmdMebL9F21RIlPH5OQyKtaLjAC aVv0b/mLNqJ4nhL4DXHxEqtju9peMicog9bnjNtmsNyWVl/wxRgwjm4cljWTbUer6F/A uJiVa8qOT12Q+1jmP1gTfAuwwGs56IJQA0Lgil7QEwzbzpFNIJ8Z6DZNkgNFMx2E6LAJ LaSHSItICUNMsPiMge4O4HhFKU5BoCvn2kdZeq+aHl2fI+GvJXZ3w62Y0V4eSkaLdwjJ /V1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=aLV0CF57edhnO+Yi0RAt5gJKhT87LHNREaBPsrajes0=; b=W8Yn7GGanW93/issbna4o8j09BojaXBGTZengcDgxg/F6lcetOWpdTobEFF+wjwt1d syUFzpc/I8OR3/vBEqBV9lFm7Nb/Kojjs6MTNBfo6hx9/jIYPhKRR04Av5lzxihEmHcS 8UM5htzZjaEZzjojR3ekIkBwGS339t4W7zGDFwmHyPwsKicyoAJNcWZXoPRQGbQgSgrb Qb4rPfbt6ePhR9wBVAUJrPescDCFOVp0iPDF7RaGmuqqhdxKo0jiHxqSxp33zVhxobfT tyiHNIX7gR+0Glox5rHyVurOA0Vbd39mA77aWQw8xtiPZra5M2kCa0to7nbg5NEX8Q10 nMDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=lVS9wWbn; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="I5Fxbe/f"; 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=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a05640227d400b0046b5106d52esi17023963ede.467.2022.12.29.10.22.10; Thu, 29 Dec 2022 10:22:24 -0800 (PST) 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; dkim=pass header.i=@sholland.org header.s=fm3 header.b=lVS9wWbn; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="I5Fxbe/f"; 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=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233928AbiL2SPi (ORCPT + 62 others); Thu, 29 Dec 2022 13:15:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233880AbiL2SPe (ORCPT ); Thu, 29 Dec 2022 13:15:34 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E831582D for ; Thu, 29 Dec 2022 10:15:33 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B62D532005C1; Thu, 29 Dec 2022 13:15:31 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 29 Dec 2022 13:15:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672337731; x=1672424131; bh=aL V0CF57edhnO+Yi0RAt5gJKhT87LHNREaBPsrajes0=; b=lVS9wWbnizn7DCDLlF kqtb1fNKzGtDRNaw88SgtTv7qoUOabeOED3pTdtOl3EKHB9F+t5v1yVxKtd4MM6y zHOOzbgyw3AzZ2XSnGyE8WHKG/378kYNYjIFDIR7gzNTb/jfows+KKPjyGs/o7EJ 5XHoy+1MxJf4Xr3UgyyonAOoVCjzHvKmUw50B9osRzseWj1S+2zLjWmRfIalvs39 PdYsXt/palbh5QSTlbypCs7Mn1M59ZDaeVxHYtb5lgrA8kprAC4Ed+U6Zk9QFVk2 GnF8LTZTBgtDPifo4vqARHwad5cYV8MIuTI9+4EIKEPDZCM4TLwyjuyo43iGf62V OWNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672337731; x=1672424131; bh=aLV0CF57edhnO +Yi0RAt5gJKhT87LHNREaBPsrajes0=; b=I5Fxbe/f1E3aeiherKYnPEQqP5X55 01qxSmqNL41L7LoJehF6WRrFp9hZryspQhILe0KqnniduAoDQf6alzostp9pJEBt NZWBCalt8xrc0OQwZ00fSAp8w+LUErLzJb3tCy+b15suTXDLdVEh5tTkfGNJljRo 60oSUBoMEKugNSgUOkgo/11ksb92SMAhJNR3jOD+mHnO82rY4jdSdc/jiP2DNgOb iy5xrOeuAFkwU6wRg6zmpr4z7MB2R6HEtBMyKiZ+C1dQzBAE7AW4P5IZsusEghBZ h9ubWknVHnWbFFbpBzETvHxHvsLV6PtvhO+CX4UwQcOkYwoSYo72ZO7Og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieeggdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 13:15:30 -0500 (EST) From: Samuel Holland To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Chen-Yu Tsai , Jernej Skrabec Cc: Boris Brezillon , Samuel Holland , Brian Norris , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 1/7] mtd: rawnand: sunxi: Clean up chips after failed init Date: Thu, 29 Dec 2022 12:15:20 -0600 Message-Id: <20221229181526.53766-2-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221229181526.53766-1-samuel@sholland.org> References: <20221229181526.53766-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 If a chip fails to initialize, we need to clean up any chips that were already initialized/registered. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: Samuel Holland --- drivers/mtd/nand/raw/sunxi_nand.c | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index ea953e31933e..2ee86f7b0905 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1950,6 +1950,25 @@ static const struct nand_controller_ops sunxi_nand_controller_ops = { .exec_op = sunxi_nfc_exec_op, }; +static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) +{ + struct sunxi_nand_chip *sunxi_nand; + struct nand_chip *chip; + int ret; + + while (!list_empty(&nfc->chips)) { + sunxi_nand = list_first_entry(&nfc->chips, + struct sunxi_nand_chip, + node); + chip = &sunxi_nand->nand; + ret = mtd_device_unregister(nand_to_mtd(chip)); + WARN_ON(ret); + nand_cleanup(chip); + sunxi_nand_ecc_cleanup(sunxi_nand); + list_del(&sunxi_nand->node); + } +} + static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, struct device_node *np) { @@ -2053,6 +2072,7 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) ret = sunxi_nand_chip_init(dev, nfc, nand_np); if (ret) { of_node_put(nand_np); + sunxi_nand_chips_cleanup(nfc); return ret; } } @@ -2060,25 +2080,6 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) return 0; } -static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) -{ - struct sunxi_nand_chip *sunxi_nand; - struct nand_chip *chip; - int ret; - - while (!list_empty(&nfc->chips)) { - sunxi_nand = list_first_entry(&nfc->chips, - struct sunxi_nand_chip, - node); - chip = &sunxi_nand->nand; - ret = mtd_device_unregister(nand_to_mtd(chip)); - WARN_ON(ret); - nand_cleanup(chip); - sunxi_nand_ecc_cleanup(sunxi_nand); - list_del(&sunxi_nand->node); - } -} - static int sunxi_nfc_dma_init(struct sunxi_nfc *nfc, struct resource *r) { int ret; -- 2.37.4