ext2: Check return value from ext2_get_group_desc()
authorJan Kara <jack@suse.cz>
Tue, 9 Aug 2016 08:07:52 +0000 (10:07 +0200)
committerJan Kara <jack@suse.cz>
Tue, 9 Aug 2016 08:12:28 +0000 (10:12 +0200)
ext2_get_group_desc() can return NULL if there is some error. This
usually means there is some programming error in the ext2 driver itself
but let's be defensive and handle that case.

Coverity-id: 115628
Signed-off-by: Jan Kara <jack@suse.cz>
fs/ext2/ialloc.c

index efe5fb21c5332197e9bb4ebe302fa408d3be5e38..04e73a99902b75ce2a436ced96782bb7d01049af 100644 (file)
@@ -465,6 +465,11 @@ struct inode *ext2_new_inode(struct inode *dir, umode_t mode,
 
        for (i = 0; i < sbi->s_groups_count; i++) {
                gdp = ext2_get_group_desc(sb, group, &bh2);
+               if (!gdp) {
+                       if (++group == sbi->s_groups_count)
+                               group = 0;
+                       continue;
+               }
                brelse(bitmap_bh);
                bitmap_bh = read_inode_bitmap(sb, group);
                if (!bitmap_bh) {