From patchwork Mon Aug 26 15:30:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13778071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6CD8EC5472D for ; Mon, 26 Aug 2024 15:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lsUAW421feHZLLrllyEzrWeyn6bG6Cl3vLexu1MBLcQ=; b=cVZNIydjkqbFK00Sm3bR+1m9zT Z0/ckbVfZQHzzzjDFyQcLsQAIVKB0guVPMeQufVNgkkyxYAG9CGx4Ym2TjlIKGDx/DSDF31nOpv/+ SA8EVvI+nzTNVXPdAUJuY8BaAxFE9FDJIOdPCmktYzWkONRMSXFRbikjRcBA5A428380MnhtzS97E qIoJzCuCImU6NU6uy9EcRTosy58vsyMtfhY71HqM2Gh5aY/rXESays7w58ehBd4HOFxLXcnlq9cP2 hfoZvP45tibPuh3LsENR1ZkNUXFGxWaKgu5xEijg2jln4buVMwIS297919vkdixfhhEhPtKlQK5ga HOhw2YjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sibhY-00000007pgY-0J9o; Mon, 26 Aug 2024 15:32:16 +0000 Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sibfj-00000007p55-1fKz; Mon, 26 Aug 2024 15:30:25 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 686AAE0009; Mon, 26 Aug 2024 15:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1724686221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lsUAW421feHZLLrllyEzrWeyn6bG6Cl3vLexu1MBLcQ=; b=g58JW+ktxXELaoG423XuQGR7u0DVJX1EDzrb7kIO8lLpoIDgIm82owuF6qdbxI5FjxlMfe BnfkjRJq0G6nO1/RNJUCpvXTTYgM8N7pCvtVJPqFPpaDpstQmtwLFwAitgJvxzNMbMBxiU DXPeZxg2SF0rPTZB9njnOCxOkABUifmRKOLl0kLQXAK+THDmPhR3eCopgl7ozjH+e6u/jc YYzzUHfh4F8BWMaHWvXw9de0NdCmwJX+NGG9BCBxnIQTLEPqpf16FFA6pw1JxSRi+WxgSN VqoBVwXVwo6C5c6yEc4DBoJr8SmRzIIIs+VXIqmVtL1PYWsOrae+pEf3u4Us6g== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Matthias Brugger , AngeloGioacchino Del Regno , , Thomas Petazzoni , Miquel Raynal Subject: [PATCH next 1/2] mtd: rawnand: mtk: Factorize out the logic cleaning mtk chips Date: Mon, 26 Aug 2024 17:30:18 +0200 Message-ID: <20240826153019.67106-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240826_083023_906991_5A3016A3 X-CRM114-Status: GOOD ( 11.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There are some un-freed resources in one of the error path which would benefit from a helper going through all the registered mtk chips one by one and perform all the necessary cleanup. This is precisely what the remove path does, so let's extract the logic in a helper. There is no functional change. Signed-off-by: Miquel Raynal Reviewed-by: Pratyush Yadav Reviewed-by: Matthias Brugger --- drivers/mtd/nand/raw/mtk_nand.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index d65e6371675b..bf845dd16737 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -1429,6 +1429,23 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, return 0; } +static void mtk_nfc_nand_chips_cleanup(struct mtk_nfc *nfc) +{ + struct mtk_nfc_nand_chip *mtk_chip; + struct nand_chip *chip; + int ret; + + while (!list_empty(&nfc->chips)) { + mtk_chip = list_first_entry(&nfc->chips, + struct mtk_nfc_nand_chip, node); + chip = &mtk_chip->nand; + ret = mtd_device_unregister(nand_to_mtd(chip)); + WARN_ON(ret); + nand_cleanup(chip); + list_del(&mtk_chip->node); + } +} + static int mtk_nfc_nand_chips_init(struct device *dev, struct mtk_nfc *nfc) { struct device_node *np = dev->of_node; @@ -1567,20 +1584,8 @@ static int mtk_nfc_probe(struct platform_device *pdev) static void mtk_nfc_remove(struct platform_device *pdev) { struct mtk_nfc *nfc = platform_get_drvdata(pdev); - struct mtk_nfc_nand_chip *mtk_chip; - struct nand_chip *chip; - int ret; - - while (!list_empty(&nfc->chips)) { - mtk_chip = list_first_entry(&nfc->chips, - struct mtk_nfc_nand_chip, node); - chip = &mtk_chip->nand; - ret = mtd_device_unregister(nand_to_mtd(chip)); - WARN_ON(ret); - nand_cleanup(chip); - list_del(&mtk_chip->node); - } + mtk_nfc_nand_chips_cleanup(nfc); mtk_ecc_release(nfc->ecc); }