summaryrefslogtreecommitdiffstats
path: root/fs/ext2/namei.c
diff options
context:
space:
mode:
authorzhangyi (F) <yi.zhang@huawei.com>2020-06-08 11:40:42 +0800
committerJan Kara <jack@suse.cz>2020-07-09 08:14:00 +0200
commitb4962091a54c8c332e4c6c211a86b7f6d6e1f759 (patch)
treefafbe783a18a79e193fa2b2bf84b01479b915dee /fs/ext2/namei.c
parent1fcbcf06e4f159e0db39a53fe258336febbba804 (diff)
downloadlinux-stable-b4962091a54c8c332e4c6c211a86b7f6d6e1f759.tar.gz
linux-stable-b4962091a54c8c332e4c6c211a86b7f6d6e1f759.tar.bz2
linux-stable-b4962091a54c8c332e4c6c211a86b7f6d6e1f759.zip
ext2: propagate errors up to ext2_find_entry()'s callers
The same to commit <36de928641ee4> (ext4: propagate errors up to ext4_find_entry()'s callers') in ext4, also return error instead of NULL pointer in case of some error happens in ext2_find_entry() (e.g. -ENOMEM or -EIO). This could avoid a negative dentry cache entry installed even it failed to read directory block due to IO error. Link: https://lore.kernel.org/r/20200608034043.10451-1-yi.zhang@huawei.com Signed-off-by: zhangyi (F) <yi.zhang@huawei.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext2/namei.c')
-rw-r--r--fs/ext2/namei.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index ba3e3e075891..9a6ab213bc4d 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -56,12 +56,15 @@ 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;
+ ino_t ino = 0;
+ int res;
if (dentry->d_name.len > EXT2_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
- ino = ext2_inode_by_name(dir, &dentry->d_name);
+ res = ext2_inode_by_name(dir, &dentry->d_name, &ino);
+ if (res)
+ return ERR_PTR(res);
inode = NULL;
if (ino) {
inode = ext2_iget(dir->i_sb, ino);
@@ -78,7 +81,12 @@ 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);
- unsigned long ino = ext2_inode_by_name(d_inode(child), &dotdot);
+ ino_t ino = 0;
+ 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));
@@ -274,7 +282,11 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
if (err)
goto out;
- de = ext2_find_entry (dir, &dentry->d_name, &page);
+ de = ext2_find_entry(dir, &dentry->d_name, &page);
+ if (IS_ERR(de)) {
+ err = PTR_ERR(de);
+ goto out;
+ }
if (!de) {
err = -ENOENT;
goto out;
@@ -330,7 +342,11 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
if (err)
goto out;
- old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
+ old_de = ext2_find_entry(old_dir, &old_dentry->d_name, &old_page);
+ if (IS_ERR(old_de)) {
+ err = PTR_ERR(old_de);
+ goto out;
+ }
if (!old_de) {
err = -ENOENT;
goto out;
@@ -352,7 +368,11 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
goto out_dir;
err = -ENOENT;
- new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page);
+ 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);