diff mbox series

[next,1/2] mtd: rawnand: mtk: Factorize out the logic cleaning mtk chips

Message ID 20240826153019.67106-1-miquel.raynal@bootlin.com (mailing list archive)
State New, archived
Headers show
Series [next,1/2] mtd: rawnand: mtk: Factorize out the logic cleaning mtk chips | expand

Commit Message

Miquel Raynal Aug. 26, 2024, 3:30 p.m. UTC
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 <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/raw/mtk_nand.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

Comments

Pratyush Yadav Sept. 4, 2024, 2:15 p.m. UTC | #1
On Mon, Aug 26 2024, Miquel Raynal wrote:

> 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 <miquel.raynal@bootlin.com>

Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Matthias Brugger Sept. 6, 2024, 3:01 p.m. UTC | #2
On 26/08/2024 17:30, Miquel Raynal wrote:
> 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 <miquel.raynal@bootlin.com>

Reviewed-by: Matthias Brugger <matthias.bgg@kernel.org>

> ---
>   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);
>   }
>
Miquel Raynal Sept. 6, 2024, 3:02 p.m. UTC | #3
On Mon, 2024-08-26 at 15:30:18 UTC, Miquel Raynal wrote:
> 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 <miquel.raynal@bootlin.com>
> Reviewed-by: Pratyush Yadav <pratyush@kernel.org>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel
diff mbox series

Patch

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);
 }