aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mtd
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2016-02-29 07:20:28 -0500
committerBrian Norris <computersforpeace@gmail.com>2016-04-03 19:46:24 -0400
commitfddcca5107051adf9e4481d2a79ae0616577fd2c (patch)
tree04c0d7b4c592fef44d0200344aa9090e09bf21cd /include/linux/mtd
parent20c07a5bf094198ff2382aa5e7c930b3c9807792 (diff)
mtd: avoid stack overflow in MTD CFI code
When map_word gets too large, we use a lot of kernel stack, and for MTD_MAP_BANK_WIDTH_32, this means we use more than the recommended 1024 bytes in a number of functions: drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_write_buffers': drivers/mtd/chips/cfi_cmdset_0020.c:651:1: warning: the frame size of 1336 bytes is larger than 1024 bytes [-Wframe-larger-than=] drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_erase_varsize': drivers/mtd/chips/cfi_cmdset_0020.c:972:1: warning: the frame size of 1208 bytes is larger than 1024 bytes [-Wframe-larger-than=] drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer': drivers/mtd/chips/cfi_cmdset_0001.c:1835:1: warning: the frame size of 1240 bytes is larger than 1024 bytes [-Wframe-larger-than=] This can be avoided if all operations on the map word are done indirectly and the stack gets reused between the calls. We can mostly achieve this by selecting MTD_COMPLEX_MAPPINGS whenever MTD_MAP_BANK_WIDTH_32 is set, but for the case that no other bank width is enabled, we also need to use a non-constant map_bankwidth() to convince the compiler to use less stack. Signed-off-by: Arnd Bergmann <arnd@arndb.de> [Brian: this patch mostly achieves its goal by forcing MTD_COMPLEX_MAPPINGS (and the accompanying indirection) for 256-bit mappings; the rest of the change is mostly a wash, though it helps reduce stack size slightly. If we really care about supporting 256-bit mappings though, we should consider rewriting some of this code to avoid keeping and assigning so many 256-bit objects on the stack.] Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'include/linux/mtd')
-rw-r--r--include/linux/mtd/map.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
index 5e0eb7ccabd4..3aa56e3104bb 100644
--- a/include/linux/mtd/map.h
+++ b/include/linux/mtd/map.h
@@ -122,18 +122,13 @@
122#endif 122#endif
123 123
124#ifdef CONFIG_MTD_MAP_BANK_WIDTH_32 124#ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
125# ifdef map_bankwidth 125/* always use indirect access for 256-bit to preserve kernel stack */
126# undef map_bankwidth 126# undef map_bankwidth
127# define map_bankwidth(map) ((map)->bankwidth) 127# define map_bankwidth(map) ((map)->bankwidth)
128# undef map_bankwidth_is_large 128# undef map_bankwidth_is_large
129# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8) 129# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
130# undef map_words 130# undef map_words
131# define map_words(map) map_calc_words(map) 131# define map_words(map) map_calc_words(map)
132# else
133# define map_bankwidth(map) 32
134# define map_bankwidth_is_large(map) (1)
135# define map_words(map) map_calc_words(map)
136# endif
137#define map_bankwidth_is_32(map) (map_bankwidth(map) == 32) 132#define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
138#undef MAX_MAP_BANKWIDTH 133#undef MAX_MAP_BANKWIDTH
139#define MAX_MAP_BANKWIDTH 32 134#define MAX_MAP_BANKWIDTH 32