We should return NULL value in error path of alloc_inode(), otherwise,
VFS will treat any non-null return value as value inode, result in
invalid pointer dereference.

Reviewed-by: Gao Xiang <[email protected]>
Signed-off-by: Chao Yu <[email protected]>
---
 fs/erofs/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index e6d4efd7c043..3fcb56fd988e 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -40,12 +40,12 @@ static struct inode *alloc_inode(struct super_block *sb)
        struct erofs_vnode *vi =
                kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
 
-       if (vi != NULL) {
-               /* zero out everything except vfs_inode */
-               memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode));
-               return &vi->vfs_inode;
-       }
-       return ERR_PTR(-ENOMEM);
+       if (!vi)
+               return NULL;
+
+       /* zero out everything except vfs_inode */
+       memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode));
+       return &vi->vfs_inode;
 }
 
 static void i_callback(struct rcu_head *head)
-- 
2.18.0.rc1

-- 
Linux-erofs mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linux-erofs

Reply via email to