ext4: silence UBSAN in ext4_mb_init()
[deliverable/linux.git] / fs / ext4 / mballoc.c
index 50e05df28f665d56a096f671929e23b715e00f2e..c1ab3ec30423f65878789c6602cb63dc82b6746f 100644 (file)
@@ -119,7 +119,7 @@ MODULE_PARM_DESC(mballoc_debug, "Debugging level for ext4's mballoc");
  *
  *
  * one block each for bitmap and buddy information.  So for each group we
- * take up 2 blocks. A page can contain blocks_per_page (PAGE_CACHE_SIZE /
+ * take up 2 blocks. A page can contain blocks_per_page (PAGE_SIZE /
  * blocksize) blocks.  So it can have information regarding groups_per_page
  * which is blocks_per_page/2
  *
@@ -807,7 +807,7 @@ static void mb_regenerate_buddy(struct ext4_buddy *e4b)
  *
  * one block each for bitmap and buddy information.
  * So for each group we take up 2 blocks. A page can
- * contain blocks_per_page (PAGE_CACHE_SIZE / blocksize)  blocks.
+ * contain blocks_per_page (PAGE_SIZE / blocksize)  blocks.
  * So it can have information regarding groups_per_page which
  * is blocks_per_page/2
  *
@@ -839,7 +839,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore, gfp_t gfp)
        sb = inode->i_sb;
        ngroups = ext4_get_groups_count(sb);
        blocksize = 1 << inode->i_blkbits;
-       blocks_per_page = PAGE_CACHE_SIZE / blocksize;
+       blocks_per_page = PAGE_SIZE / blocksize;
 
        groups_per_page = blocks_per_page >> 1;
        if (groups_per_page == 0)
@@ -993,7 +993,7 @@ static int ext4_mb_get_buddy_page_lock(struct super_block *sb,
        e4b->bd_buddy_page = NULL;
        e4b->bd_bitmap_page = NULL;
 
-       blocks_per_page = PAGE_CACHE_SIZE / sb->s_blocksize;
+       blocks_per_page = PAGE_SIZE / sb->s_blocksize;
        /*
         * the buddy cache inode stores the block bitmap
         * and buddy information in consecutive blocks.
@@ -1028,11 +1028,11 @@ static void ext4_mb_put_buddy_page_lock(struct ext4_buddy *e4b)
 {
        if (e4b->bd_bitmap_page) {
                unlock_page(e4b->bd_bitmap_page);
-               page_cache_release(e4b->bd_bitmap_page);
+               put_page(e4b->bd_bitmap_page);
        }
        if (e4b->bd_buddy_page) {
                unlock_page(e4b->bd_buddy_page);
-               page_cache_release(e4b->bd_buddy_page);
+               put_page(e4b->bd_buddy_page);
        }
 }
 
@@ -1125,7 +1125,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
        might_sleep();
        mb_debug(1, "load group %u\n", group);
 
-       blocks_per_page = PAGE_CACHE_SIZE / sb->s_blocksize;
+       blocks_per_page = PAGE_SIZE / sb->s_blocksize;
        grp = ext4_get_group_info(sb, group);
 
        e4b->bd_blkbits = sb->s_blocksize_bits;
@@ -1167,7 +1167,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
                         * is yet to initialize the same. So
                         * wait for it to initialize.
                         */
-                       page_cache_release(page);
+                       put_page(page);
                page = find_or_create_page(inode->i_mapping, pnum, gfp);
                if (page) {
                        BUG_ON(page->mapping != inode->i_mapping);
@@ -1203,7 +1203,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
        page = find_get_page_flags(inode->i_mapping, pnum, FGP_ACCESSED);
        if (page == NULL || !PageUptodate(page)) {
                if (page)
-                       page_cache_release(page);
+                       put_page(page);
                page = find_or_create_page(inode->i_mapping, pnum, gfp);
                if (page) {
                        BUG_ON(page->mapping != inode->i_mapping);
@@ -1238,11 +1238,11 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
 
 err:
        if (page)
-               page_cache_release(page);
+               put_page(page);
        if (e4b->bd_bitmap_page)
-               page_cache_release(e4b->bd_bitmap_page);
+               put_page(e4b->bd_bitmap_page);
        if (e4b->bd_buddy_page)
-               page_cache_release(e4b->bd_buddy_page);
+               put_page(e4b->bd_buddy_page);
        e4b->bd_buddy = NULL;
        e4b->bd_bitmap = NULL;
        return ret;
@@ -1257,15 +1257,16 @@ static int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group,
 static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)
 {
        if (e4b->bd_bitmap_page)
-               page_cache_release(e4b->bd_bitmap_page);
+               put_page(e4b->bd_bitmap_page);
        if (e4b->bd_buddy_page)
-               page_cache_release(e4b->bd_buddy_page);
+               put_page(e4b->bd_buddy_page);
 }
 
 
 static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
 {
        int order = 1;
+       int bb_incr = 1 << (e4b->bd_blkbits - 1);
        void *bb;
 
        BUG_ON(e4b->bd_bitmap == e4b->bd_buddy);
@@ -1278,7 +1279,8 @@ static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
                        /* this block is part of buddy of order 'order' */
                        return order;
                }
-               bb += 1 << (e4b->bd_blkbits - order);
+               bb += bb_incr;
+               bb_incr >>= 1;
                order++;
        }
        return 0;
@@ -2583,7 +2585,7 @@ int ext4_mb_init(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        unsigned i, j;
-       unsigned offset;
+       unsigned offset, offset_incr;
        unsigned max;
        int ret;
 
@@ -2612,11 +2614,13 @@ int ext4_mb_init(struct super_block *sb)
 
        i = 1;
        offset = 0;
+       offset_incr = 1 << (sb->s_blocksize_bits - 1);
        max = sb->s_blocksize << 2;
        do {
                sbi->s_mb_offsets[i] = offset;
                sbi->s_mb_maxs[i] = max;
-               offset += 1 << (sb->s_blocksize_bits - i);
+               offset += offset_incr;
+               offset_incr = offset_incr >> 1;
                max = max >> 1;
                i++;
        } while (i <= sb->s_blocksize_bits + 1);
@@ -2833,8 +2837,8 @@ static void ext4_free_data_callback(struct super_block *sb,
                /* No more items in the per group rb tree
                 * balance refcounts from ext4_mb_free_metadata()
                 */
-               page_cache_release(e4b.bd_buddy_page);
-               page_cache_release(e4b.bd_bitmap_page);
+               put_page(e4b.bd_buddy_page);
+               put_page(e4b.bd_bitmap_page);
        }
        ext4_unlock_group(sb, entry->efd_group);
        kmem_cache_free(ext4_free_data_cachep, entry);
@@ -4385,9 +4389,9 @@ static int ext4_mb_release_context(struct ext4_allocation_context *ac)
                ext4_mb_put_pa(ac, ac->ac_sb, pa);
        }
        if (ac->ac_bitmap_page)
-               page_cache_release(ac->ac_bitmap_page);
+               put_page(ac->ac_bitmap_page);
        if (ac->ac_buddy_page)
-               page_cache_release(ac->ac_buddy_page);
+               put_page(ac->ac_buddy_page);
        if (ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC)
                mutex_unlock(&ac->ac_lg->lg_mutex);
        ext4_mb_collect_stats(ac);
@@ -4599,8 +4603,8 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
                 * otherwise we'll refresh it from
                 * on-disk bitmap and lose not-yet-available
                 * blocks */
-               page_cache_get(e4b->bd_buddy_page);
-               page_cache_get(e4b->bd_bitmap_page);
+               get_page(e4b->bd_buddy_page);
+               get_page(e4b->bd_bitmap_page);
        }
        while (*n) {
                parent = *n;
@@ -4935,7 +4939,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
         * boundary.
         */
        if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) {
-               ext4_warning(sb, "too much blocks added to group %u\n",
+               ext4_warning(sb, "too much blocks added to group %u",
                             block_group);
                err = -EINVAL;
                goto error_return;
This page took 0.027053 seconds and 5 git commands to generate.