btrfs-progs: mkfs: avoid positive return value from cleanup_temp_chunks
authorQu Wenruo <wqu@suse.com>
Thu, 19 Oct 2017 05:41:34 +0000 (13:41 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 14 Nov 2017 14:59:00 +0000 (15:59 +0100)
Since we're calling btrfs_search_slot() the return value can be
positive.  However we just pass that return value out, causing undefined
return value.

This can cause mkfs to return 1, which indicates something wrong.

Fix it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
mkfs/main.c

index 1b4cabc..94f54d8 100644 (file)
@@ -1350,6 +1350,9 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
                ret = btrfs_search_slot(trans, root, &key, &path, 0, 0);
                if (ret < 0)
                        goto out;
+               /* Don't pollute ret for >0 case */
+               if (ret > 0)
+                       ret = 0;
 
                btrfs_item_key_to_cpu(path.nodes[0], &found_key,
                                      path.slots[0]);