summaryrefslogtreecommitdiff
path: root/fs/ext2/namei.c
diff options
context:
space:
mode:
authorzhangyi (F) <yi.zhang@huawei.com>2020-06-08 06:40:43 +0300
committerJan Kara <jack@suse.cz>2020-07-09 09:14:00 +0300
commita43850a380ef56009ce721737b0c08984b663b99 (patch)
treed45a10e93abd3bde1853699d93c45cc40706d99b /fs/ext2/namei.c
parentb4962091a54c8c332e4c6c211a86b7f6d6e1f759 (diff)
downloadlinux-a43850a380ef56009ce721737b0c08984b663b99.tar.xz
ext2: ext2_find_entry() return -ENOENT if no entry found
Almost all callers of ext2_find_entry() transform NULL return value to -ENOENT, so just let ext2_find_entry() retuen -ENOENT instead of NULL if no valid entry found, and also switch to check the return value of ext2_inode_by_name() in ext2_lookup() and ext2_get_parent(). Link: https://lore.kernel.org/r/20200608034043.10451-2-yi.zhang@huawei.com Signed-off-by: zhangyi (F) <yi.zhang@huawei.com> Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext2/namei.c')
-rw-r--r--fs/ext2/namei.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 9a6ab213bc4d..5bf2c145643b 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -56,17 +56,18 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, unsigned int flags)
{
struct inode * inode;
- ino_t ino = 0;
+ ino_t ino;
int res;
if (dentry->d_name.len > EXT2_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
res = ext2_inode_by_name(dir, &dentry->d_name, &ino);
- if (res)
- return ERR_PTR(res);
- inode = NULL;
- if (ino) {
+ if (res) {
+ if (res != -ENOENT)
+ return ERR_PTR(res);
+ inode = NULL;
+ } else {
inode = ext2_iget(dir->i_sb, ino);
if (inode == ERR_PTR(-ESTALE)) {
ext2_error(dir->i_sb, __func__,
@@ -81,14 +82,13 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, uns
struct dentry *ext2_get_parent(struct dentry *child)
{
struct qstr dotdot = QSTR_INIT("..", 2);
- ino_t ino = 0;
+ ino_t ino;
int res;
res = ext2_inode_by_name(d_inode(child), &dotdot, &ino);
if (res)
return ERR_PTR(res);
- if (!ino)
- return ERR_PTR(-ENOENT);
+
return d_obtain_alias(ext2_iget(child->d_sb, ino));
}
@@ -287,10 +287,6 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
err = PTR_ERR(de);
goto out;
}
- if (!de) {
- err = -ENOENT;
- goto out;
- }
err = ext2_delete_entry (de, page);
if (err)
@@ -347,10 +343,6 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
err = PTR_ERR(old_de);
goto out;
}
- if (!old_de) {
- err = -ENOENT;
- goto out;
- }
if (S_ISDIR(old_inode->i_mode)) {
err = -EIO;
@@ -367,14 +359,11 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
if (dir_de && !ext2_empty_dir (new_inode))
goto out_dir;
- err = -ENOENT;
new_de = ext2_find_entry(new_dir, &new_dentry->d_name, &new_page);
if (IS_ERR(new_de)) {
err = PTR_ERR(new_de);
goto out_dir;
}
- if (!new_de)
- goto out_dir;
ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
new_inode->i_ctime = current_time(new_inode);
if (dir_de)