diff mbox series

[v2,02/52] ffspart, libflash: Fix stack size warnings

Message ID 20190221062851.21958-3-andrew@aj.id.au
State Accepted
Headers show
Series ipmi-hiomap: Tests and fixes for event handling | expand

Commit Message

Andrew Jeffery Feb. 21, 2019, 6:28 a.m. UTC
libflash/file.c: In function 'file_erase':
    libflash/file.c:134:1: error: the frame size of 4128 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
     }
     ^

and

    ffspart.c: In function ‘main’:
    ffspart.c:529:1: error: the frame size of 4864 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
     }
     ^

In both cases, mark the local variables as static to avoid the stack.

The static approach is valid for file.c as the buffer is always filled
with `~0`. Given it's now going to be in .bss due to static we have to
still perform the memset(), but racing memset()s in this fashion won't
be harmful, just wasteful.

For ffspart.c's main(), there are bigger problems if that needs to be
re-entrant.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 external/ffspart/ffspart.c | 4 +++-
 libflash/file.c            | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c
index bb46a9eaf311..9fc015cf872b 100644
--- a/external/ffspart/ffspart.c
+++ b/external/ffspart/ffspart.c
@@ -350,7 +350,9 @@  static void print_help(const char *pname)
 
 int main(int argc, char *argv[])
 {
-	char *pnor = NULL, *input = NULL, line[MAX_LINE];
+	static char line[MAX_LINE];
+
+	char *pnor = NULL, *input = NULL;
 	bool toc_created = false, bad_input = false, allow_empty = false;
 	uint32_t block_size = 0, block_count = 0;
 	struct ffs_hdr *tocs[MAX_TOCS] = { 0 };
diff --git a/libflash/file.c b/libflash/file.c
index 72765b5777f9..d790e29df103 100644
--- a/libflash/file.c
+++ b/libflash/file.c
@@ -117,7 +117,7 @@  static int file_write(struct blocklevel_device *bl, uint64_t dst, const void *sr
  */
 static int file_erase(struct blocklevel_device *bl, uint64_t dst, uint64_t len)
 {
-	char buf[4096];
+	static char buf[4096];
 	int i = 0;
 	int rc;