]> git.hungrycats.org Git - linux/commitdiff
btrfs: do not ignore error from btrfs_next_leaf() when inserting checksums
authorFilipe Manana <fdmanana@suse.com>
Mon, 18 May 2020 11:15:09 +0000 (12:15 +0100)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 1 Sep 2020 04:40:57 +0000 (00:40 -0400)
[ Upstream commit 7e4a3f7ed5d54926ec671bbb13e171cfe179cc50 ]

We are currently treating any non-zero return value from btrfs_next_leaf()
the same way, by going to the code that inserts a new checksum item in the
tree. However if btrfs_next_leaf() returns an error (a value < 0), we
should just stop and return the error, and not behave as if nothing has
happened, since in that case we do not have a way to know if there is a
next leaf or we are currently at the last leaf already.

So fix that by returning the error from btrfs_next_leaf().

Signed-off-by: Filipe Manana <fdmanana@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>
(cherry picked from commit 2a005026102e1bc337718a4a9812b6fdd5d9a712)

fs/btrfs/file-item.c

index 6f18333e83c33cc3d6cd83692b5a4c9553a40e9b..50d83708303a884d6a84c0ac82a4c1f5d49648f3 100644 (file)
@@ -798,10 +798,12 @@ again:
                nritems = btrfs_header_nritems(path->nodes[0]);
                if (!nritems || (path->slots[0] >= nritems - 1)) {
                        ret = btrfs_next_leaf(root, path);
-                       if (ret == 1)
+                       if (ret < 0) {
+                               goto out;
+                       } else if (ret > 0) {
                                found_next = 1;
-                       if (ret != 0)
                                goto insert;
+                       }
                        slot = path->slots[0];
                }
                btrfs_item_key_to_cpu(path->nodes[0], &found_key, slot);