| From a21f8a98c4c9b845de5d5b296f34e962583dcc6f Mon Sep 17 00:00:00 2001 |
| From: Miquel Raynal <miquel.raynal@bootlin.com> |
| Date: Tue, 19 May 2020 15:00:10 +0200 |
| Subject: [PATCH] mtd: rawnand: oxnas: Unregister all devices on error |
| |
| commit b60391eb17b2956ff2fc4c348e5a464da21ff9cb upstream. |
| |
| On error, the oxnas probe path just frees the device which failed and |
| aborts the probe, leaving unreleased resources. |
| |
| Fix this situation by calling mtd_device_unregister()/nand_cleanup() |
| on these. |
| |
| Fixes: 668592492409 ("mtd: nand: Add OX820 NAND Support") |
| Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> |
| Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-38-miquel.raynal@bootlin.com |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/mtd/nand/raw/oxnas_nand.c b/drivers/mtd/nand/raw/oxnas_nand.c |
| index bead5ac70160..6ae71e2a0ed5 100644 |
| --- a/drivers/mtd/nand/raw/oxnas_nand.c |
| +++ b/drivers/mtd/nand/raw/oxnas_nand.c |
| @@ -82,6 +82,7 @@ static int oxnas_nand_probe(struct platform_device *pdev) |
| struct resource *res; |
| int count = 0; |
| int err = 0; |
| + int i; |
| |
| /* Allocate memory for the device structure (and zero it) */ |
| oxnas = devm_kzalloc(&pdev->dev, sizeof(*oxnas), |
| @@ -161,6 +162,13 @@ static int oxnas_nand_probe(struct platform_device *pdev) |
| |
| err_release_child: |
| of_node_put(nand_np); |
| + |
| + for (i = 0; i < oxnas->nchips; i++) { |
| + chip = oxnas->chips[i]; |
| + WARN_ON(mtd_device_unregister(nand_to_mtd(chip))); |
| + nand_cleanup(chip); |
| + } |
| + |
| err_clk_unprepare: |
| clk_disable_unprepare(oxnas->clk); |
| return err; |
| -- |
| 2.27.0 |
| |