Commit e18db412 authored by Johannes Thumshirn's avatar Johannes Thumshirn Committed by Greg Kroah-Hartman

btrfs: improve error handling of btrfs_add_link

[ Upstream commit 1690dd41 ]

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 fe66a05a (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: default avatarJohannes Thumshirn <>
Reviewed-by: default avatarDavid Sterba <>
Signed-off-by: default avatarDavid Sterba <>
Signed-off-by: default avatarSasha Levin <>
parent d9ef1519
......@@ -6419,14 +6419,19 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment