Skip to contentSkip to conversation

btrfs: fix stack size warning in btrfs_test_delayed_refs()

PATCH In review Arnd Bergmann 2 participants 2 messages Dec 12, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix stack size warning in btrfs_test_delayed_refs()

From: Arnd Bergmann <[email protected]>

The newly added code has a btrfs_transaction structure on the stack, which makes it somewhat too large for 32-bit kernels:

fs/btrfs/tests/delayed-refs-tests.c: In function 'btrfs_test_delayed_refs':
fs/btrfs/tests/delayed-refs-tests.c:1012:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
1012 | }

      | ^

Change this to a dynamic allocation instead.

Fixes fa3dda44871b ("btrfs: selftests: add delayed ref self test cases")
---
 fs/btrfs/tests/delayed-refs-tests.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/tests/delayed-refs-tests.c +6 -3
index 9b469791c20a..86333521b94a 100644
@@ -978,7 +978,6 @@ static int select_delayed_refs_test(struct btrfs_trans_handle *trans)
 
 int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize)
 {
-	struct btrfs_transaction transaction;
 	struct btrfs_trans_handle trans;
 	struct btrfs_fs_info *fs_info;
 	int ret;
@@ -991,8 +990,10 @@ int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize)
 		return -ENOMEM;
 	}
 	btrfs_init_dummy_trans(&trans, fs_info);
-	btrfs_init_dummy_transaction(&transaction, fs_info);
-	trans.transaction = &transaction;
+	trans.transaction = kmalloc(sizeof(*trans.transaction), GFP_KERNEL);
+	if (!trans.transaction)
+		goto out;
+	btrfs_init_dummy_transaction(trans.transaction, fs_info);
 
 	ret = simple_tests(&trans);
 	if (!ret) {
@@ -1007,6 +1008,8 @@ int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize)
 
 	if (!ret)
 		ret = select_delayed_refs_test(&trans);
+	kfree(trans.transaction);
+out:
 	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
Signature · 1 line
2.39.5
#1 lore raw
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added code has a btrfs_transaction structure on the stack, which makes it somewhat too large for 32-bit kernels:

fs/btrfs/tests/delayed-refs-tests.c: In function 'btrfs_test_delayed_refs':
fs/btrfs/tests/delayed-refs-tests.c:1012:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
1012 | }

Quoted 6 lines
      | ^

Change this to a dynamic allocation instead.

Fixes fa3dda44871b ("btrfs: selftests: add delayed ref self test cases")

Thanks, this was fixed last week but was not updated in the branch pulled by linux-next.