put_mtd_device is match to get_mtd_device to decount users, and also fix
the potential memory leakage when failure happens.

Signed-off-by: Zumeng Chen <zumeng.c...@windriver.com>
---
 fs/yaffs2/yaffs_vfs.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/fs/yaffs2/yaffs_vfs.c b/fs/yaffs2/yaffs_vfs.c
index 5a9c295..8e103e6 100644
--- a/fs/yaffs2/yaffs_vfs.c
+++ b/fs/yaffs2/yaffs_vfs.c
@@ -2873,7 +2873,7 @@ static struct super_block *yaffs_internal_read_super(int 
yaffs_version,
        }
 
        if(yaffs_verify_mtd(mtd, yaffs_version, inband_tags) < 0)
-               return NULL;
+               goto error_to_put_mtd;
 
        /* OK, so if we got here, we have an MTD that's NAND and looks
         * like it has the right capabilities
@@ -2892,20 +2892,12 @@ static struct super_block 
*yaffs_internal_read_super(int yaffs_version,
        context = kmalloc(sizeof(struct yaffs_linux_context), GFP_KERNEL);
 
        if (!dev || !context) {
-               if (dev)
-                       kfree(dev);
-               if (context)
-                       kfree(context);
-               dev = NULL;
-               context = NULL;
-       }
 
-       if (!dev) {
                /* Deep shit could not allocate device structure */
                yaffs_trace(YAFFS_TRACE_ALWAYS,
-                       "yaffs_read_super: Failed trying to allocate struct 
yaffs_dev."
+               "yaffs_read_super: Failed trying to allocate struct yaffs_dev."
                );
-               return NULL;
+               goto  error_to_free;
        }
        memset(dev, 0, sizeof(struct yaffs_dev));
        param = &(dev->param);
@@ -3042,7 +3034,7 @@ static struct super_block *yaffs_internal_read_super(int 
yaffs_version,
                inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0, yaffs_root(dev));
 
        if (!inode)
-               return NULL;
+               goto  error_to_free;
 
        inode->i_op = &yaffs_dir_inode_operations;
        inode->i_fop = &yaffs_dir_operations;
@@ -3052,7 +3044,7 @@ static struct super_block *yaffs_internal_read_super(int 
yaffs_version,
        root = yaffs_make_root(inode);
 
        if (!root)
-               return NULL;
+               goto  error_to_free;
 
        sb->s_root = root;
        if(!dev->is_checkpointed)
@@ -3064,6 +3056,13 @@ static struct super_block *yaffs_internal_read_super(int 
yaffs_version,
 
        yaffs_trace(YAFFS_TRACE_OS, "yaffs_read_super: done");
        return sb;
+
+error_to_free:
+       kfree(dev);
+       kfree(context);
+error_to_put_mtd:
+       put_mtd_device(mtd);
+       return NULL;
 }
 
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
-- 
2.7.4

-- 
_______________________________________________
linux-yocto mailing list
linux-yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/linux-yocto

Reply via email to