Skip to contentSkip to conversation

ARM: shmobile: lager: do not annotate gpio_buttons as __initdata

PATCH New Simon Horman 3 participants 3 messages Jul 26, 2013 – Jul 30, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: shmobile: lager: do not annotate gpio_buttons as __initdata

When the gpio-keys device is registered using platform_device_register_data() the platform data argument, lager_keys_pdata is duplicated and thus should be marked as __initdata to avoid wasting memory. However, this is not true of gpio_buttons, a reference to it rather than its value is duplicated when lager_keys_pdata is duplicated.

This avoids accessing freed memory if gpio-key events occur after unused kernel memory is freed late in the kernel's boot.

This but was added when support for gpio-keys was added to lager in c3842e4fcbb7664276443b79187b7808c2e80a35
("ARM: shmobile: lager: support GPIO switches") which was included in v3.11-rc1.

---

* Noticed when adding gpio-keys support to ape6evm
* Compile tested only

---
 arch/arm/mach-shmobile/board-lager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-shmobile/board-lager.c +1 -1
index 3c67b2a..3a1a6fd 100644
@@ -63,7 +63,7 @@ static __initdata struct gpio_led_platform_data lager_leds_pdata = {
 #define GPIO_KEY(c, g, d, ...) \
 	{ .code = c, .gpio = g, .desc = d, .active_low = 1 }
 
-static __initdata struct gpio_keys_button gpio_buttons[] = {
+static struct gpio_keys_button gpio_buttons[] = {
 	GPIO_KEY(KEY_4,		RCAR_GP_PIN(1, 28),	"SW2-pin4"),
 	GPIO_KEY(KEY_3,		RCAR_GP_PIN(1, 26),	"SW2-pin3"),
 	GPIO_KEY(KEY_2,		RCAR_GP_PIN(1, 24),	"SW2-pin2"),
Signature · 1 line
1.8.3.2
maintainer
#1 lore raw

PATCH 1/1 ARM: shmobile: lager: do not annotate gpio_buttons as __initdata

Quoted 15 lines · Simon Horman

When the gpio-keys device is registered using platform_device_register_data() the platform data argument, lager_keys_pdata is duplicated and thus should be marked as __initdata to avoid wasting memory. However, this is not true of gpio_buttons, a reference to it rather than its value is duplicated when lager_keys_pdata is duplicated.

This avoids accessing freed memory if gpio-key events occur after unused kernel memory is freed late in the kernel's boot.

This but was added when support for gpio-keys was added to lager in c3842e4fcbb7664276443b79187b7808c2e80a35
("ARM: shmobile: lager: support GPIO switches") which was included in v3.11-rc1.

Quoted 6 lines

---

* Noticed when adding gpio-keys support to ape6evm
* Compile tested only

I just got around to test this patch on a Lager board, works well. Thanks!

#2 lore raw

PATCH 1/1 ARM: shmobile: lager: do not annotate gpio_buttons as __initdata

Quoted 19 lines · Magnus Damm
Quoted 17 lines · Simon Horman

When the gpio-keys device is registered using platform_device_register_data() the platform data argument, lager_keys_pdata is duplicated and thus should be marked as __initdata to avoid wasting memory. However, this is not true of gpio_buttons, a reference to it rather than its value is duplicated when lager_keys_pdata is duplicated.

This avoids accessing freed memory if gpio-key events occur after unused kernel memory is freed late in the kernel's boot.

This but was added when support for gpio-keys was added to lager in c3842e4fcbb7664276443b79187b7808c2e80a35
("ARM: shmobile: lager: support GPIO switches") which was included in v3.11-rc1.

Quoted 8 lines
Quoted 4 lines

---

* Noticed when adding gpio-keys support to ape6evm
* Compile tested only

I just got around to test this patch on a Lager board, works well. Thanks!

Thanks, I have queued this up for v3.11 in the fixes-for-v3.11 branch.