btrfs: tree-log: check btrfs_lookup_data_extent return value
authorMarcos Paulo de Souza <mpdesouza@suse.com>
Mon, 2 Aug 2021 12:34:00 +0000 (09:34 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:40:31 +0000 (13:40 +0200)
[ Upstream commit 3736127a3aa805602b7a2ad60ec9cfce68065fbb ]

Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if
the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return
values bellow zero if an error happened.

Function replay_one_extent currently checks if the search found
something (0 returned) and increments the reference, and if not, it
seems to evaluate as 'not found'.

Fix the condition by checking if the value was bellow zero and return
early.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/tree-log.c

index f36928efcf92de1252daafa7902a43f57a1df997..ec25e5eab3499cc13e5d5aef5a83db66cec2bff6 100644 (file)
@@ -708,7 +708,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
                         */
                        ret = btrfs_lookup_data_extent(fs_info, ins.objectid,
                                                ins.offset);
-                       if (ret == 0) {
+                       if (ret < 0) {
+                               goto out;
+                       } else if (ret == 0) {
                                btrfs_init_generic_ref(&ref,
                                                BTRFS_ADD_DELAYED_REF,
                                                ins.objectid, ins.offset, 0);