gfs2: Minor gfs2_alloc_inode cleanup
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 24 Jul 2019 11:05:38 +0000 (13:05 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 9 Aug 2019 16:00:52 +0000 (17:00 +0100)
In gfs2_alloc_inode, when kmem_cache_alloc cannot allocate a new object, return
NULL immediately.  The code currently relies on the fact that i_inode is the
first member in struct gfs2_inode and so ip and &ip->i_inode evaluate to the
same address, but that isn't immediately obvious.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Bob Peterson <rpeterso@redhat.com>
fs/gfs2/super.c

index 0acc5834f653d159b7845784a9b976bac141b06b..644c70ae09f74e3f07be3205fd283285de92e412 100644 (file)
@@ -1722,13 +1722,13 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
        struct gfs2_inode *ip;
 
        ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
-       if (ip) {
-               ip->i_flags = 0;
-               ip->i_gl = NULL;
-               memset(&ip->i_res, 0, sizeof(ip->i_res));
-               RB_CLEAR_NODE(&ip->i_res.rs_node);
-               ip->i_rahead = 0;
-       }
+       if (!ip)
+               return NULL;
+       ip->i_flags = 0;
+       ip->i_gl = NULL;
+       memset(&ip->i_res, 0, sizeof(ip->i_res));
+       RB_CLEAR_NODE(&ip->i_res.rs_node);
+       ip->i_rahead = 0;
        return &ip->i_inode;
 }