From: Zhang Z. <zhe...@hu...> - 2014-12-17 08:40:31
|
Adjust the free order of squashfs_fill_super(), to meet the allocation sequence. Signed-off-by: Zhang Zhen <zhe...@hu...> --- fs/squashfs/super.c | 65 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index 5056bab..f3db491 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c @@ -115,7 +115,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) ERROR("unable to read squashfs_super_block\n"); err = PTR_ERR(sblk); sblk = NULL; - goto failed_mount; + goto free_s_fs_info; } err = -EINVAL; @@ -126,7 +126,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) if (!silent) ERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(sb->s_bdev, b)); - goto failed_mount; + goto free_sblk; } /* Check the MAJOR & MINOR versions and lookup compression type */ @@ -135,19 +135,19 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) le16_to_cpu(sblk->s_minor), le16_to_cpu(sblk->compression)); if (msblk->decompressor == NULL) - goto failed_mount; + goto free_sblk; /* Check the filesystem does not extend beyond the end of the block device */ msblk->bytes_used = le64_to_cpu(sblk->bytes_used); if (msblk->bytes_used < 0 || msblk->bytes_used > i_size_read(sb->s_bdev->bd_inode)) - goto failed_mount; + goto free_sblk; /* Check block size for sanity */ msblk->block_size = le32_to_cpu(sblk->block_size); if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE) - goto failed_mount; + goto free_sblk; /* * Check the system page size is not larger than the filesystem @@ -156,22 +156,22 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) if (PAGE_CACHE_SIZE > msblk->block_size) { ERROR("Page size > filesystem block size (%d). This is " "currently not supported!\n", msblk->block_size); - goto failed_mount; + goto free_sblk; } /* Check block log for sanity */ msblk->block_log = le16_to_cpu(sblk->block_log); if (msblk->block_log > SQUASHFS_FILE_MAX_LOG) - goto failed_mount; + goto free_sblk; /* Check that block_size and block_log match */ if (msblk->block_size != (1 << msblk->block_log)) - goto failed_mount; + goto free_sblk; /* Check the root inode for sanity */ root_inode = le64_to_cpu(sblk->root_inode); if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE) - goto failed_mount; + goto free_sblk; msblk->inode_table = le64_to_cpu(sblk->inode_table_start); msblk->directory_table = le64_to_cpu(sblk->directory_table_start); @@ -204,21 +204,21 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) msblk->block_cache = squashfs_cache_init("metadata", SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE); if (msblk->block_cache == NULL) - goto failed_mount; + goto free_sblk; /* Allocate read_page block */ msblk->read_page = squashfs_cache_init("data", squashfs_max_decompressors(), msblk->block_size); if (msblk->read_page == NULL) { ERROR("Failed to allocate read_page block\n"); - goto failed_mount; + goto free_block_cache; } msblk->stream = squashfs_decompressor_setup(sb, flags); if (IS_ERR(msblk->stream)) { err = PTR_ERR(msblk->stream); msblk->stream = NULL; - goto failed_mount; + goto free_read_page; } /* Handle xattrs */ @@ -237,7 +237,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) err = PTR_ERR(msblk->xattr_id_table); msblk->xattr_id_table = NULL; if (err != -ENOTSUPP) - goto failed_mount; + goto destroy_msblk; } next_table = msblk->xattr_table; @@ -250,7 +250,7 @@ allocate_id_index_table: ERROR("unable to read id index table\n"); err = PTR_ERR(msblk->id_table); msblk->id_table = NULL; - goto failed_mount; + goto free_xattr_id_table; } next_table = le64_to_cpu(msblk->id_table[0]); @@ -266,7 +266,7 @@ allocate_id_index_table: ERROR("unable to read inode lookup table\n"); err = PTR_ERR(msblk->inode_lookup_table); msblk->inode_lookup_table = NULL; - goto failed_mount; + goto free_id_table; } next_table = le64_to_cpu(msblk->inode_lookup_table[0]); @@ -281,7 +281,7 @@ handle_fragments: SQUASHFS_CACHED_FRAGMENTS, msblk->block_size); if (msblk->fragment_cache == NULL) { err = -ENOMEM; - goto failed_mount; + goto free_inode_lookup_table; } /* Allocate and read fragment index table */ @@ -291,7 +291,7 @@ handle_fragments: ERROR("unable to read fragment index table\n"); err = PTR_ERR(msblk->fragment_index); msblk->fragment_index = NULL; - goto failed_mount; + goto free_fragment_cache; } next_table = le64_to_cpu(msblk->fragment_index[0]); @@ -299,27 +299,27 @@ check_directory_table: /* Sanity check directory_table */ if (msblk->directory_table > next_table) { err = -EINVAL; - goto failed_mount; + goto free_fragment_index; } /* Sanity check inode_table */ if (msblk->inode_table >= msblk->directory_table) { err = -EINVAL; - goto failed_mount; + goto free_fragment_index; } /* allocate root */ root = new_inode(sb); if (!root) { err = -ENOMEM; - goto failed_mount; + goto free_fragment_index; } err = squashfs_read_inode(root, root_inode); if (err) { make_bad_inode(root); iput(root); - goto failed_mount; + goto free_fragment_index; } insert_inode_hash(root); @@ -327,25 +327,34 @@ check_directory_table: if (sb->s_root == NULL) { ERROR("Root inode create failed\n"); err = -ENOMEM; - goto failed_mount; + goto free_fragment_index; } TRACE("Leaving squashfs_fill_super\n"); kfree(sblk); return 0; -failed_mount: - squashfs_cache_delete(msblk->block_cache); +free_fragment_index: + kfree(msblk->fragment_index); +free_fragment_cache: squashfs_cache_delete(msblk->fragment_cache); - squashfs_cache_delete(msblk->read_page); - squashfs_decompressor_destroy(msblk); +free_inode_lookup_table: kfree(msblk->inode_lookup_table); - kfree(msblk->fragment_index); +free_id_table: kfree(msblk->id_table); +free_xattr_id_table: kfree(msblk->xattr_id_table); +destroy_msblk: + squashfs_decompressor_destroy(msblk); +free_read_page: + squashfs_cache_delete(msblk->read_page); +free_block_cache: + squashfs_cache_delete(msblk->block_cache); +free_sblk: + kfree(sblk); +free_s_fs_info: kfree(sb->s_fs_info); sb->s_fs_info = NULL; - kfree(sblk); return err; } -- 1.8.1.4 . |