Skip to contentSkip to conversation

MTD: cfi: reduce stack size

PATCH Superseded Arnd Bergmann 2 participants 2 messages Mar 9, 2015 Memory technology devices (MTD)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 MTD: cfi: reduce stack size

The cfi_staa_write_buffers function uses a large amount of kernel stack whenever CONFIG_MTD_MAP_BANK_WIDTH_32 is set, and that results in a warning on ARM allmodconfig builds:

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 1208 bytes is larger than 1024 bytes [-Wframe-larger-than=]

It turns out that this is largely a result of a suboptimal implementation of map_word_andequal(). Replacing this function with a straightforward one reduces the stack size in this function by exactly 200 bytes, shrinks the .text segment for this file from 27648 bytes to 26608 bytes, and makes the warning go away.

include/linux/mtd/map.h +9 -1
index 5f487d776411..7b5841663d4f 100644
@@ -314,7 +314,15 @@ static inline map_word map_word_or(struct map_info *map, map_word val1, map_word
 	return r;
 }
 
-#define map_word_andequal(m, a, b, z) map_word_equal(m, z, map_word_and(m, a, b))
+static inline int map_word_andequal(struct map_info *map, map_word val1, map_word val2, map_word val3)
+{
+	int i;
+	for (i=0; i < map_words(map); i++) {
+		if ((val1.x[i] & val2.x[i]) != val3.x[i])
+			return 0;
+	}
+	return 1;
+}
 
 static inline int map_word_bitsset(struct map_info *map, map_word val1, map_word val2)
 {
#1 lore raw

Hello.

Quoted 20 lines · Arnd Bergmann

The cfi_staa_write_buffers function uses a large amount of kernel stack whenever CONFIG_MTD_MAP_BANK_WIDTH_32 is set, and that results in a warning on ARM allmodconfig builds:

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 1208 bytes is larger than 1024 bytes [-Wframe-larger-than=]

It turns out that this is largely a result of a suboptimal implementation of map_word_andequal(). Replacing this function with a straightforward one reduces the stack size in this function by exactly 200 bytes, shrinks the .text segment for this file from 27648 bytes to 26608 bytes, and makes the warning go away.

include/linux/mtd/map.h +0 -0
index 5f487d776411..7b5841663d4f 100644

include/linux/mtd/map.h static inline map_word map_word_or(struct map_info *map, map_word val1, map_word · line 319

Quoted 7 lines
include/linux/mtd/map.h +3 -1
@@ -314,7 +314,15 @@ static inline map_word map_word_or(struct map_info *map, map_word val1, map_word
  	return r;
  }
 
-#define map_word_andequal(m, a, b, z) map_word_equal(m, z, map_word_and(m, a, b))
+static inline int map_word_andequal(struct map_info *map, map_word val1, map_word val2, map_word val3)
+{
+	int i;

I think empty line is needed here.

include/linux/mtd/map.h static inline map_word map_word_or(struct map_info *map, map_word val1, map_word · line 320

Quoted 1 line
include/linux/mtd/map.h +1 -0
+	for (i=0; i < map_words(map); i++) {

Could you please be consistent and surround all binary operators with
spaces, like on the line below?

include/linux/mtd/map.h static inline map_word map_word_or(struct map_info *map, map_word val1, map_word · line 325

Quoted 5 lines
include/linux/mtd/map.h +5 -0
+		if ((val1.x[i] & val2.x[i]) != val3.x[i])
+			return 0;
+	}
+	return 1;
+}

[...]

WBR, Sergei