Merge tag 'folio-6.0' of git://git.infradead.org/users/willy/pagecache
[platform/kernel/linux-starfive.git] / fs / ext2 / super.c
index a1c1263..27a0a8c 100644 (file)
@@ -1057,9 +1057,10 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
                        sbi->s_frags_per_group);
                goto failed_mount;
        }
-       if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
+       if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
+           sbi->s_inodes_per_group > sb->s_blocksize * 8) {
                ext2_msg(sb, KERN_ERR,
-                       "error: #inodes per group too big: %lu",
+                       "error: invalid #inodes per group: %lu",
                        sbi->s_inodes_per_group);
                goto failed_mount;
        }
@@ -1069,6 +1070,13 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
        sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
                                le32_to_cpu(es->s_first_data_block) - 1)
                                        / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
+       if ((u64)sbi->s_groups_count * sbi->s_inodes_per_group !=
+           le32_to_cpu(es->s_inodes_count)) {
+               ext2_msg(sb, KERN_ERR, "error: invalid #inodes: %u vs computed %llu",
+                        le32_to_cpu(es->s_inodes_count),
+                        (u64)sbi->s_groups_count * sbi->s_inodes_per_group);
+               goto failed_mount;
+       }
        db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
                   EXT2_DESC_PER_BLOCK(sb);
        sbi->s_group_desc = kmalloc_array(db_count,
@@ -1488,8 +1496,7 @@ static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
                len = i_size-off;
        toread = len;
        while (toread > 0) {
-               tocopy = sb->s_blocksize - offset < toread ?
-                               sb->s_blocksize - offset : toread;
+               tocopy = min_t(size_t, sb->s_blocksize - offset, toread);
 
                tmp_bh.b_state = 0;
                tmp_bh.b_size = sb->s_blocksize;
@@ -1527,8 +1534,7 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
        struct buffer_head *bh;
 
        while (towrite > 0) {
-               tocopy = sb->s_blocksize - offset < towrite ?
-                               sb->s_blocksize - offset : towrite;
+               tocopy = min_t(size_t, sb->s_blocksize - offset, towrite);
 
                tmp_bh.b_state = 0;
                tmp_bh.b_size = sb->s_blocksize;