btrfs: simplify error handling logic for btrfs_link()
authorFilipe Manana <fdmanana@suse.com>
Fri, 25 Jul 2025 16:08:13 +0000 (17:08 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 21 Aug 2025 22:58:28 +0000 (00:58 +0200)
commit5bb00879cb23db7e5e2fc0aa47b5ce3b1c713d8a
treee511c2b00b185ba82b7e48e3643a5bbecef78ee8
parente87e953bb20629ca1f008f8146c38e313e5ed319
btrfs: simplify error handling logic for btrfs_link()

Instead of incrementing the inode's link count and refcount early before
adding the link, updating the inode and deleting orphan item, do it after
all those steps succeeded right before calling d_instantiate(). This makes
the error handling logic simpler by avoiding the need for the 'drop_inode'
variable to signal if we need to undo the link count increment and the
inode refcount increase under the 'fail' label.

This also reduces the level of indentation by one, making the code easier
to read.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c