btrfs: return error value if create_io_em failed in cow_file_range
authorSu Yue <suy.fnst@cn.fujitsu.com>
Wed, 30 May 2018 08:48:56 +0000 (16:48 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 30 May 2018 14:51:08 +0000 (16:51 +0200)
In cow_file_range(), create_io_em() may fail, but its return value is
not recorded.  Then return value may be 0 even it failed which is a
wrong behavior.

Let cow_file_range() return PTR_ERR(em) if create_io_em() failed.

Fixes: 6f9994dbabe5 ("Btrfs: create a helper to create em for IO")
CC: stable@vger.kernel.org # 4.11+
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index 7148abaf1da32a985e7ee3dbb12d1186249c7f98..f81a48c47fe05fa1453f662237a166c3f70f022b 100644 (file)
@@ -1018,8 +1018,10 @@ static noinline int cow_file_range(struct inode *inode,
                                  ram_size, /* ram_bytes */
                                  BTRFS_COMPRESS_NONE, /* compress_type */
                                  BTRFS_ORDERED_REGULAR /* type */);
-               if (IS_ERR(em))
+               if (IS_ERR(em)) {
+                       ret = PTR_ERR(em);
                        goto out_reserve;
+               }
                free_extent_map(em);
 
                ret = btrfs_add_ordered_extent(inode, start, ins.objectid,