]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: adjust return values of btrfs_inode_by_name
authorSu Yue <suy.fnst@cn.fujitsu.com>
Mon, 5 Mar 2018 09:13:37 +0000 (17:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Dec 2020 07:34:40 +0000 (08:34 +0100)
commit 005d67127fa9dfb3382f2c9e918feed7a243a7fe upstream

Previously, btrfs_inode_by_name() returned 0 which left caller to check
objectid of location even location if the type was invalid.

Let btrfs_inode_by_name() return -EUCLEAN if a corrupted location of a
dir entry is found.  Removal of label out_err also simplifies the
function.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ drop unlikely ]
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c

index e985e820724e1a36f3211dc6f6a3e5b213ad3ed8..1459010cfde5624c2178a8cd96ac3e61621f091a 100644 (file)
@@ -5585,7 +5585,8 @@ no_delete:
 
 /*
  * this returns the key found in the dir entry in the location pointer.
- * If no dir entries were found, location->objectid is 0.
+ * If no dir entries were found, returns -ENOENT.
+ * If found a corrupted location in dir entry, returns -EUCLEAN.
  */
 static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
                               struct btrfs_key *location)
@@ -5603,27 +5604,27 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
 
        di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(BTRFS_I(dir)),
                        name, namelen, 0);
-       if (IS_ERR(di))
+       if (!di) {
+               ret = -ENOENT;
+               goto out;
+       }
+       if (IS_ERR(di)) {
                ret = PTR_ERR(di);
-
-       if (IS_ERR_OR_NULL(di))
-               goto out_err;
+               goto out;
+       }
 
        btrfs_dir_item_key_to_cpu(path->nodes[0], di, location);
        if (location->type != BTRFS_INODE_ITEM_KEY &&
            location->type != BTRFS_ROOT_ITEM_KEY) {
+               ret = -EUCLEAN;
                btrfs_warn(root->fs_info,
 "%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, location(%llu %u %llu))",
                           __func__, name, btrfs_ino(BTRFS_I(dir)),
                           location->objectid, location->type, location->offset);
-               goto out_err;
        }
 out:
        btrfs_free_path(path);
        return ret;
-out_err:
-       location->objectid = 0;
-       goto out;
 }
 
 /*
@@ -5924,9 +5925,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
        if (ret < 0)
                return ERR_PTR(ret);
 
-       if (location.objectid == 0)
-               return ERR_PTR(-ENOENT);
-
        if (location.type == BTRFS_INODE_ITEM_KEY) {
                inode = btrfs_iget(dir->i_sb, &location, root, NULL);
                return inode;