btrfs: reada: Fix returned errno code
authorLuis de Bethencourt <luisbg@osg.samsung.com>
Tue, 20 Oct 2015 13:56:23 +0000 (14:56 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Oct 2015 16:29:50 +0000 (18:29 +0200)
reada is using -1 instead of the -ENOMEM defined macro to specify that
a buffer allocation failed. Since the error number is propagated, the
caller will get a -EPERM which is the wrong error condition.

Also, updating the caller to return the exact value from
reada_add_block.

Smatch tool warning:
reada_add_block() warn: returning -1 instead of -ENOMEM is sloppy

Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reada.c

index 4645cd16d5ba22d94396eec0f00e1243371eeb7c..619f92963e27102fb47a6f119b65451bdf959bef 100644 (file)
@@ -569,7 +569,7 @@ static int reada_add_block(struct reada_control *rc, u64 logical,
        rec = kzalloc(sizeof(*rec), GFP_NOFS);
        if (!rec) {
                reada_extent_put(root->fs_info, re);
-               return -1;
+               return -ENOMEM;
        }
 
        rec->rc = rc;
@@ -918,6 +918,7 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
        u64 start;
        u64 generation;
        int level;
+       int ret;
        struct extent_buffer *node;
        static struct btrfs_key max_key = {
                .objectid = (u64)-1,
@@ -943,9 +944,10 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
        generation = btrfs_header_generation(node);
        free_extent_buffer(node);
 
-       if (reada_add_block(rc, start, &max_key, level, generation)) {
+       ret = reada_add_block(rc, start, &max_key, level, generation);
+       if (ret) {
                kfree(rc);
-               return ERR_PTR(-ENOMEM);
+               return ERR_PTR(ret);
        }
 
        reada_start_machine(root->fs_info);