Skip to content

Commit d60c536

Browse files
arndbtytso
authored andcommitted
ext4: kunit: use dynamic inode allocation
Storing an inode structure on the stack pushes some functions over the warning limit for stack frame size: In file included from fs/ext4/mballoc.c:7039: fs/ext4/mballoc-test.c:506:13: error: stack frame size (1032) exceeds limit (1024) in 'test_mark_diskspace_used' [-Werror,-Wframe-larger-than] 506 | static void test_mark_diskspace_used(struct kunit *test) | ^ Use kunit_kzalloc() for all inodes. There may be a better way to do it by preallocating the inode, which would result in a larger rework. Fixes: 2b81493 ("ext4: Add unit test for ext4_mb_mark_diskspace_used") Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Kemeng Shi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 07be778 commit d60c536

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

fs/ext4/mballoc-test.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,19 @@ static void mbt_kunit_exit(struct kunit *test)
332332
static void test_new_blocks_simple(struct kunit *test)
333333
{
334334
struct super_block *sb = (struct super_block *)test->priv;
335-
struct inode inode = { .i_sb = sb, };
335+
struct inode *inode;
336336
struct ext4_allocation_request ar;
337337
ext4_group_t i, goal_group = TEST_GOAL_GROUP;
338338
int err = 0;
339339
ext4_fsblk_t found;
340340
struct ext4_sb_info *sbi = EXT4_SB(sb);
341341

342-
ar.inode = &inode;
342+
inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
343+
if (!inode)
344+
return;
345+
346+
inode->i_sb = sb;
347+
ar.inode = inode;
343348

344349
/* get block at goal */
345350
ar.goal = ext4_group_first_block_no(sb, goal_group);
@@ -441,15 +446,20 @@ test_free_blocks_simple_range(struct kunit *test, ext4_group_t goal_group,
441446
{
442447
struct super_block *sb = (struct super_block *)test->priv;
443448
struct ext4_sb_info *sbi = EXT4_SB(sb);
444-
struct inode inode = { .i_sb = sb, };
449+
struct inode *inode;
445450
ext4_fsblk_t block;
446451

452+
inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
453+
if (!inode)
454+
return;
455+
inode->i_sb = sb;
456+
447457
if (len == 0)
448458
return;
449459

450460
block = ext4_group_first_block_no(sb, goal_group) +
451461
EXT4_C2B(sbi, start);
452-
ext4_free_blocks_simple(&inode, block, len);
462+
ext4_free_blocks_simple(inode, block, len);
453463
validate_free_blocks_simple(test, sb, goal_group, start, len);
454464
mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb));
455465
}
@@ -506,16 +516,21 @@ test_mark_diskspace_used_range(struct kunit *test,
506516
static void test_mark_diskspace_used(struct kunit *test)
507517
{
508518
struct super_block *sb = (struct super_block *)test->priv;
509-
struct inode inode = { .i_sb = sb, };
519+
struct inode *inode;
510520
struct ext4_allocation_context ac;
511521
struct test_range ranges[TEST_RANGE_COUNT];
512522
int i;
513523

514524
mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
515525

526+
inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
527+
if (!inode)
528+
return;
529+
inode->i_sb = sb;
530+
516531
ac.ac_status = AC_STATUS_FOUND;
517532
ac.ac_sb = sb;
518-
ac.ac_inode = &inode;
533+
ac.ac_inode = inode;
519534
for (i = 0; i < TEST_RANGE_COUNT; i++)
520535
test_mark_diskspace_used_range(test, &ac, ranges[i].start,
521536
ranges[i].len);

0 commit comments

Comments
 (0)