mtd: nand: nandsim: use the mtd instance embedded in struct nand_chip

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 12 15:59:21 PST 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=ed10f1655832de0c7e26d4c76ef1bad3bbf87b51
Commit:     ed10f1655832de0c7e26d4c76ef1bad3bbf87b51
Parent:     a008deb1655ca7301dd388237aa60f867d9f784c
Author:     Boris BREZILLON <boris.brezillon at free-electrons.com>
AuthorDate: Thu Dec 10 09:00:13 2015 +0100
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Fri Dec 18 10:54:41 2015 -0800

    mtd: nand: nandsim: use the mtd instance embedded in struct nand_chip
    
    struct nand_chip now embeds an mtd device. Make use of this mtd instance.
    
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/nandsim.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index eb2a567..442eeaf 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2236,13 +2236,13 @@ static int __init ns_init_module(void)
 	}
 
 	/* Allocate and initialize mtd_info, nand_chip and nandsim structures */
-	nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
-				+ sizeof(struct nandsim), GFP_KERNEL);
-	if (!nsmtd) {
+	chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim),
+		       GFP_KERNEL);
+	if (!chip) {
 		NS_ERR("unable to allocate core structures.\n");
 		return -ENOMEM;
 	}
-	chip        = (struct nand_chip *)(nsmtd + 1);
+	nsmtd       = nand_to_mtd(chip);
         nsmtd->priv = (void *)chip;
 	nand        = (struct nandsim *)(chip + 1);
 	chip->priv  = (void *)nand;
@@ -2392,7 +2392,7 @@ err_exit:
 	for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i)
 		kfree(nand->partitions[i].name);
 error:
-	kfree(nsmtd);
+	kfree(chip);
 	free_lists();
 
 	return retval;
@@ -2413,7 +2413,7 @@ static void __exit ns_cleanup_module(void)
 	nand_release(nsmtd); /* Unregister driver */
 	for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i)
 		kfree(ns->partitions[i].name);
-	kfree(nsmtd);        /* Free other structures */
+	kfree(mtd_to_nand(nsmtd));        /* Free other structures */
 	free_lists();
 }
 



More information about the linux-mtd-cvs mailing list