Skip to contentSkip to conversation

gpio: make several const arrays static, shrinks object size

PATCH In review Colin King 3 participants 3 messages Apr 18, 2018 – Apr 26, 2018

Subsystems (5)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 gpio: make several const arrays static, shrinks object size

From: Colin Ian King <[email protected]>

Don't populate the const read-only arrays 'port' on the stack but instead make them static. Makes the object code smaller:

Before:

  text    data     bss     dec    hex filename
  8542    4088     672   13302   33f6 drivers/gpio/gpio-gpio-mm.o
 10959    4952     832   16743   4167 drivers/gpio/gpio-104-dio-48e.o
  9022    5064    1408   15494   3c86 drivers/gpio/gpio-104-idi-48.o

After:

  text    data     bss     dec    hex filename
  8372    4144     672   13188   3384 drivers/gpio/gpio-gpio-mm.o
 10790    5008     832   16630   40f6 drivers/gpio/gpio-104-dio-48e.o
  8853    5152    1408   15413   3c35 linux/drivers/gpio/gpio-104-idi-48.o

(gcc version 7.2.0 x86_64)

---
 drivers/gpio/gpio-104-dio-48e.c | 2 +-
 drivers/gpio/gpio-104-idi-48.c  | 2 +-
 drivers/gpio/gpio-gpio-mm.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpio-104-dio-48e.c +1 -1
index 31e22c93e844..9c4e07fcb74b 100644
@@ -188,7 +188,7 @@ static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 {
 	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
 	size_t i;
-	const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
+	static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
 	const unsigned int gpio_reg_size = 8;
 	unsigned int bits_offset;
 	size_t word_index;
drivers/gpio/gpio-104-idi-48.c +1 -1
index f35632609379..2c9738adb3a6 100644
@@ -94,7 +94,7 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 {
 	struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
 	size_t i;
-	const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
+	static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
 	const unsigned int gpio_reg_size = 8;
 	unsigned int bits_offset;
 	size_t word_index;
drivers/gpio/gpio-gpio-mm.c +1 -1
index d496cc56c2a2..b56ff2efbf36 100644
@@ -177,7 +177,7 @@ static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 {
 	struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
 	size_t i;
-	const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
+	static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
 	const unsigned int gpio_reg_size = 8;
 	unsigned int bits_offset;
 	size_t word_index;
Signature · 1 line
2.17.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Colin King

From: Colin Ian King <[email protected]>

Don't populate the const read-only arrays 'port' on the stack but instead make them static. Makes the object code smaller:

Before:

 text    data     bss     dec    hex filename
 8542    4088     672   13302   33f6 drivers/gpio/gpio-gpio-mm.o
10959    4952     832   16743   4167 drivers/gpio/gpio-104-dio-48e.o
 9022    5064    1408   15494   3c86 drivers/gpio/gpio-104-idi-48.o

After:

Quoted 8 lines
 text    data     bss     dec    hex filename
 8372    4144     672   13188   3384 drivers/gpio/gpio-gpio-mm.o
10790    5008     832   16630   40f6 drivers/gpio/gpio-104-dio-48e.o
 8853    5152    1408   15413   3c35 linux/drivers/gpio/gpio-104-idi-48.o

(gcc version 7.2.0 x86_64)

#2 lore raw
In reply to Colin King
Quoted 12 lines · Colin King

From: Colin Ian King <[email protected]>

Don't populate the const read-only arrays 'port' on the stack but instead make them static. Makes the object code smaller:

Before:

  text    data     bss     dec    hex filename
  8542    4088     672   13302   33f6 drivers/gpio/gpio-gpio-mm.o
 10959    4952     832   16743   4167 drivers/gpio/gpio-104-dio-48e.o
  9022    5064    1408   15494   3c86 drivers/gpio/gpio-104-idi-48.o

After:

Quoted 8 lines
  text    data     bss     dec    hex filename
  8372    4144     672   13188   3384 drivers/gpio/gpio-gpio-mm.o
 10790    5008     832   16630   40f6 drivers/gpio/gpio-104-dio-48e.o
  8853    5152    1408   15413   3c35 linux/drivers/gpio/gpio-104-idi-48.o

(gcc version 7.2.0 x86_64)

I had already applied some part of the patch.

Dropped patches to one file for this reason.

Please check the result.

Patch applied!

Yours,
Linus Walleij