mtd: nand: gpmi: Fix gpmi_nand_init() error path

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Jul 13 10:59:13 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=4d02423e9afe6c46142ce98bbcaf5167316dbfbf
Commit:     4d02423e9afe6c46142ce98bbcaf5167316dbfbf
Parent:     d7e578c8118113789b7abd2977e208c64d6f8465
Author:     Boris Brezillon <boris.brezillon at free-electrons.com>
AuthorDate: Mon Apr 10 10:35:17 2017 +0200
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Thu Jun 1 10:09:27 2017 +0200

    mtd: nand: gpmi: Fix gpmi_nand_init() error path
    
    The GPMI driver is wrongly assuming that nand_release() can safely be
    called on an uninitialized/unregistered NAND device.
    
    Add a new err_nand_cleanup label in the error path and only execute if
    nand_scan_tail() succeeded.
    
    Note that we now call nand_cleanup() instead of nand_release()
    (nand_release() is actually grouping the mtd_device_unregister() and
    nand_cleanup() in one call) because there's no point in trying to
    unregister a device that has never been registered.
    
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
    Reviewed-by: Marek Vasut <marek.vasut at gmail.com>
    Acked-by: Han Xu <han.xu at nxp.com>
    Reviewed-by: Marek Vasut <marek.vasut at gmail.com>
---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 9b777be..f7ac81e 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -2055,18 +2055,20 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 
 	ret = nand_boot_init(this);
 	if (ret)
-		goto err_out;
+		goto err_nand_cleanup;
 	ret = chip->scan_bbt(mtd);
 	if (ret)
-		goto err_out;
+		goto err_nand_cleanup;
 
 	ret = mtd_device_register(mtd, NULL, 0);
 	if (ret)
-		goto err_out;
+		goto err_nand_cleanup;
 	return 0;
 
+err_nand_cleanup:
+	nand_cleanup(chip);
 err_out:
-	gpmi_nand_exit(this);
+	gpmi_free_dma_buffer(this);
 	return ret;
 }
 



More information about the linux-mtd-cvs mailing list