btrfs-progs: convert: Fix inline file extent creation condition
[platform/upstream/btrfs-progs.git] / convert / source-ext2.c
index e5c2a94..a2af121 100644 (file)
@@ -95,6 +95,7 @@ static int ext2_open_fs(struct btrfs_convert_context *cctx, const char *name)
        return 0;
 fail:
        ext2fs_close(ext2_fs);
+       ext2fs_free(ext2_fs);
        return -1;
 }
 
@@ -179,6 +180,7 @@ static void ext2_close_fs(struct btrfs_convert_context *cctx)
                cctx->volume_name = NULL;
        }
        ext2fs_close(cctx->fs_data);
+       ext2fs_free(cctx->fs_data);
 }
 
 static u8 ext2_filetype_conversion_table[EXT2_FT_MAX] = {
@@ -308,8 +310,8 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
        if (ret)
                goto fail;
        if ((convert_flags & CONVERT_FLAG_INLINE_DATA) && data.first_block == 0
-           && data.num_blocks > 0
-           && inode_size <= BTRFS_MAX_INLINE_DATA_SIZE(root)) {
+           && data.num_blocks > 0 && inode_size < sectorsize
+           && inode_size <= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) {
                u64 num_bytes = data.num_blocks * sectorsize;
                u64 disk_bytenr = data.disk_block * sectorsize;
                u64 nbytes;
@@ -420,8 +422,7 @@ static int ext2_xattr_check_entry(struct ext2_ext_attr_entry *entry,
 {
        size_t value_size = entry->e_value_size;
 
-       if (entry->e_value_block != 0 || value_size > size ||
-           entry->e_value_offs + value_size > size)
+       if (value_size > size || entry->e_value_offs + value_size > size)
                return -EIO;
        return 0;
 }