[PATCH] binfmt_elf: reduce stackusage in kunit test

Arnd Bergmann posted 1 patch 3 months, 2 weeks ago
fs/tests/binfmt_elf_kunit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] binfmt_elf: reduce stackusage in kunit test
Posted by Arnd Bergmann 3 months, 2 weeks ago
From: Arnd Bergmann <arnd@arndb.de>

Constructing arrays on the stack in the test case triggers a warning
in some configurations:

fs/tests/binfmt_elf_kunit.c: In function 'total_mapping_size_test':
fs/tests/binfmt_elf_kunit.c:52:1: error: the frame size of 1448 bytes is larger than 1408 bytes [-Werror=frame-larger-than=]

Change the arrays to 'static const' to not use any stack space at all.
This is possible since the contents are never modified.

Fixes: 9e1a3ce0a952 ("binfmt_elf: Introduce KUnit test")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/tests/binfmt_elf_kunit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/tests/binfmt_elf_kunit.c b/fs/tests/binfmt_elf_kunit.c
index 11d734fec366..023042f6aeee 100644
--- a/fs/tests/binfmt_elf_kunit.c
+++ b/fs/tests/binfmt_elf_kunit.c
@@ -3,7 +3,7 @@
 
 static void total_mapping_size_test(struct kunit *test)
 {
-	struct elf_phdr empty[] = {
+	static const struct elf_phdr empty[] = {
 		{ .p_type = PT_LOAD, .p_vaddr = 0, .p_memsz = 0, },
 		{ .p_type = PT_INTERP, .p_vaddr = 10, .p_memsz = 999999, },
 	};
@@ -11,7 +11,7 @@ static void total_mapping_size_test(struct kunit *test)
 	 * readelf -lW /bin/mount | grep '^  .*0x0' | awk '{print "\t\t{ .p_type = PT_" \
 	 *				$1 ", .p_vaddr = " $3 ", .p_memsz = " $6 ", },"}'
 	 */
-	struct elf_phdr mount[] = {
+	static const struct elf_phdr mount[] = {
 		{ .p_type = PT_PHDR, .p_vaddr = 0x00000040, .p_memsz = 0x0002d8, },
 		{ .p_type = PT_INTERP, .p_vaddr = 0x00000318, .p_memsz = 0x00001c, },
 		{ .p_type = PT_LOAD, .p_vaddr = 0x00000000, .p_memsz = 0x0033a8, },
@@ -28,7 +28,7 @@ static void total_mapping_size_test(struct kunit *test)
 	};
 	size_t mount_size = 0xE070;
 	/* https://lore.kernel.org/linux-fsdevel/YfF18Dy85mCntXrx@fractal.localdomain */
-	struct elf_phdr unordered[] = {
+	static const struct elf_phdr unordered[] = {
 		{ .p_type = PT_LOAD, .p_vaddr = 0x00000000, .p_memsz = 0x0033a8, },
 		{ .p_type = PT_LOAD, .p_vaddr = 0x0000d330, .p_memsz = 0x000d40, },
 		{ .p_type = PT_LOAD, .p_vaddr = 0x00004000, .p_memsz = 0x005c91, },
-- 
2.39.5