From: HuangXiaojia <huangxiaojia2@huawei.com> hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/release-management/issues/ID5W1P ------------------ In mfs_lookup, d_splice_alias is called before mfs_install_path, making dentry of mfs connected to a tree without setting path. When mfs_get_path is called in mfs_open or mfs_lookup, the path could be null pointer. Fixes: 7a24ca94cb48 ("mfs: Add basic data operation for MFS") Signed-off-by: HuangXiaojia <huangxiaojia2@huawei.com> --- fs/mfs/inode.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/mfs/inode.c b/fs/mfs/inode.c index cbbce30db3f6..e45a5da7a67c 100644 --- a/fs/mfs/inode.c +++ b/fs/mfs/inode.c @@ -19,14 +19,12 @@ static int mfs_inode_set(struct inode *inode, void *lower_target) return 0; } -static struct dentry *_mfs_get_inode(struct dentry *dentry, - struct super_block *sb, +static struct inode *_mfs_get_inode(struct super_block *sb, struct path *lower_path, struct path *cache_path) { struct mfs_sb_info *sbi = MFS_SB(sb); - struct inode *inode, *lower_inode, *cache_inode; - struct dentry *ret; + struct inode *ret, *lower_inode, *cache_inode; lower_inode = d_inode(lower_path->dentry); cache_inode = d_inode(cache_path->dentry); @@ -49,12 +47,7 @@ static struct dentry *_mfs_get_inode(struct dentry *dentry, } /* allocate new inode for mfs */ - inode = mfs_iget(sb, lower_inode, cache_path); - if (IS_ERR(inode)) { - ret = ERR_PTR(PTR_ERR(inode)); - goto out; - } - ret = d_splice_alias(inode, dentry); + ret = mfs_iget(sb, lower_inode, cache_path); out: return ret; } @@ -125,6 +118,7 @@ static struct dentry *mfs_lookup(struct inode *dir, struct dentry *dentry, { struct path parent_lpath, parent_cpath, lpath, cpath; struct dentry *ret, *parent; + struct inode *inode; const char *name; int err; @@ -163,14 +157,21 @@ static struct dentry *mfs_lookup(struct inode *dir, struct dentry *dentry, goto cdentry_fail; } /* build the inode from lower layer */ - ret = _mfs_get_inode(dentry, dir->i_sb, &lpath, &cpath); - if (IS_ERR(ret)) { + inode = _mfs_get_inode(dir->i_sb, &lpath, &cpath); + if (IS_ERR(inode)) { path_put(&lpath); path_put(&cpath); mfs_free_dentry_info(dentry); + ret = ERR_PTR(PTR_ERR(inode)); goto out; } mfs_install_path(dentry, &lpath, &cpath); + ret = d_splice_alias(inode, dentry); + if (IS_ERR(ret)) { + path_put(&lpath); + path_put(&cpath); + mfs_free_dentry_info(dentry); + } out: mfs_put_path(&parent_lpath, &parent_cpath); dput(parent); -- 2.25.1