summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorJohannes Thumshirn <jthumshirn@suse.de>2018-12-12 15:14:17 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-01-26 09:32:39 +0100
commit310f8296d6305249ea1f4bbb6fb9a9690e003451 (patch)
treeb0b463c0ecdbce713a8d1c48751767929e049399 /fs/btrfs
parent38b17eee7074490c15128b596a35c837d9d94c60 (diff)
downloadlinux-stable-310f8296d6305249ea1f4bbb6fb9a9690e003451.tar.gz
linux-stable-310f8296d6305249ea1f4bbb6fb9a9690e003451.tar.bz2
linux-stable-310f8296d6305249ea1f4bbb6fb9a9690e003451.zip
btrfs: improve error handling of btrfs_add_link
[ Upstream commit 1690dd41e0cb1dade80850ed8a3eb0121b96d22f ] In the error handling block, err holds the return value of either btrfs_del_root_ref() or btrfs_del_inode_ref() but it hasn't been checked since it's introduction with commit fe66a05a0679 (Btrfs: improve error handling for btrfs_insert_dir_item callers) in 2012. If the error handling in the error handling fails, there's not much left to do and the abort either happened earlier in the callees or is necessary here. So if one of btrfs_del_root_ref() or btrfs_del_inode_ref() failed, abort the transaction, but still return the original code of the failure stored in 'ret' as this will be reported to the user. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/inode.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4f6dc56b4f4d..83b3a626c796 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6440,14 +6440,19 @@ fail_dir_item:
err = btrfs_del_root_ref(trans, key.objectid,
root->root_key.objectid, parent_ino,
&local_index, name, name_len);
-
+ if (err)
+ btrfs_abort_transaction(trans, err);
} else if (add_backref) {
u64 local_index;
int err;
err = btrfs_del_inode_ref(trans, root, name, name_len,
ino, parent_ino, &local_index);
+ if (err)
+ btrfs_abort_transaction(trans, err);
}
+
+ /* Return the original error code */
return ret;
}