Skip to contentSkip to conversation

Input: amikbd - Fix build if !CONFIG_HW_CONSOLE

PATCH In review Geert Uytterhoeven 2 participants 4 messages Nov 30, 2014 – Dec 4, 2014

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

PATCH v2 1/2 Input: amikbd - Fix build if !CONFIG_HW_CONSOLE

If CONFIG_HW_CONSOLE is not set:

drivers/built-in.o: In function `amikbd_probe':
amikbd.c:(.init.text+0x3e4e): undefined reference to key_maps' amikbd.c:(.init.text+0x3dd4): undefined reference to key_maps'

To fix this, extract the initialization of the console keyboard maps into amikbd_init_console_keymaps(), protected by #ifdef CONFIG_HW_CONSOLE.

---
Discovered during randconfig builds.

v2:
- No changes

---
 drivers/input/keyboard/amikbd.c | 46 ++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/input/keyboard/amikbd.c +29 -17
index 096d6067ae1f890f..4f81e65d9e35cb7d 100644
@@ -45,6 +45,7 @@ MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 MODULE_DESCRIPTION("Amiga keyboard driver");
 MODULE_LICENSE("GPL");
 
+#ifdef CONFIG_HW_CONSOLE
 static unsigned char amikbd_keycode[0x78] __initdata = {
 	[0]	 = KEY_GRAVE,
 	[1]	 = KEY_1,
@@ -144,6 +145,31 @@ static unsigned char amikbd_keycode[0x78] __initdata = {
 	[103]	 = KEY_RIGHTMETA
 };
 
+static void __init amikbd_init_console_keymaps(void)
+{
+	int i, j;
+
+	for (i = 0; i < MAX_NR_KEYMAPS; i++) {
+		static u_short temp_map[NR_KEYS] __initdata;
+		if (!key_maps[i])
+			continue;
+		memset(temp_map, 0, sizeof(temp_map));
+		for (j = 0; j < 0x78; j++) {
+			if (!amikbd_keycode[j])
+				continue;
+			temp_map[j] = key_maps[i][amikbd_keycode[j]];
+		}
+		for (j = 0; j < NR_KEYS; j++) {
+			if (!temp_map[j])
+				temp_map[j] = 0xf200;
+		}
+		memcpy(key_maps[i], temp_map, sizeof(temp_map));
+	}
+}
+#else /* !CONFIG_HW_CONSOLE */
+static inline void amikbd_init_console_keymaps(void) {}
+#endif /* !CONFIG_HW_CONSOLE */
+
 static const char *amikbd_messages[8] = {
 	[0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
 	[1] = KERN_WARNING "amikbd: keyboard lost sync\n",
@@ -186,7 +212,7 @@ static irqreturn_t amikbd_interrupt(int irq, void *data)
 static int __init amikbd_probe(struct platform_device *pdev)
 {
 	struct input_dev *dev;
-	int i, j, err;
+	int i, err;
 
 	dev = input_allocate_device();
 	if (!dev) {
@@ -207,22 +233,8 @@ static int __init amikbd_probe(struct platform_device *pdev)
 	for (i = 0; i < 0x78; i++)
 		set_bit(i, dev->keybit);
 
-	for (i = 0; i < MAX_NR_KEYMAPS; i++) {
-		static u_short temp_map[NR_KEYS] __initdata;
-		if (!key_maps[i])
-			continue;
-		memset(temp_map, 0, sizeof(temp_map));
-		for (j = 0; j < 0x78; j++) {
-			if (!amikbd_keycode[j])
-				continue;
-			temp_map[j] = key_maps[i][amikbd_keycode[j]];
-		}
-		for (j = 0; j < NR_KEYS; j++) {
-			if (!temp_map[j])
-				temp_map[j] = 0xf200;
-		}
-		memcpy(key_maps[i], temp_map, sizeof(temp_map));
-	}
+	amikbd_init_console_keymaps();
+
 	ciaa.cra &= ~0x41;	 /* serial data in, turn off TA */
 	err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
 			  dev);
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 2/2 Input: amikbd - Allocate temporary keymap buffer on the stack

Allocate the temporary buffer needed for initialization of the console keyboard maps (512 bytes, as NR_KEYS = 256) on the stack instead of statically, to reduce kernel size.

add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-512 (-512)
function old new delta
temp_map 512 - -512

---
v2:
- Allocate temp_map[] on the stack instead of using kmalloc().

---
 drivers/input/keyboard/amikbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/keyboard/amikbd.c +1 -1
index 4f81e65d9e35cb7d..60580d8104b9f970 100644
@@ -147,10 +147,10 @@ static unsigned char amikbd_keycode[0x78] __initdata = {
 
 static void __init amikbd_init_console_keymaps(void)
 {
+	unsigned short temp_map[NR_KEYS];
 	int i, j;
 
 	for (i = 0; i < MAX_NR_KEYMAPS; i++) {
-		static u_short temp_map[NR_KEYS] __initdata;
 		if (!key_maps[i])
 			continue;
 		memset(temp_map, 0, sizeof(temp_map));
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v2 2/2] Input: amikbd - Allocate temporary keymap buffer on the stack

Quoted 7 lines · Geert Uytterhoeven

Allocate the temporary buffer needed for initialization of the console keyboard maps (512 bytes, as NR_KEYS = 256) on the stack instead of statically, to reduce kernel size.

add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-512 (-512)
function old new delta
temp_map 512 - -512

So because it is marked __initdata and is placed into a separate section we have to allocate the space in the image?

Anyway, applied both, thank you.

Quoted 28 lines

---
v2:
- Allocate temp_map[] on the stack instead of using kmalloc().

---
 drivers/input/keyboard/amikbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/keyboard/amikbd.c +1 -1
index 4f81e65d9e35cb7d..60580d8104b9f970 100644
@@ -147,10 +147,10 @@ static unsigned char amikbd_keycode[0x78] __initdata = {
 
 static void __init amikbd_init_console_keymaps(void)
 {
+	unsigned short temp_map[NR_KEYS];
 	int i, j;
 
 	for (i = 0; i < MAX_NR_KEYMAPS; i++) {
-		static u_short temp_map[NR_KEYS] __initdata;
 		if (!key_maps[i])
 			continue;
 		memset(temp_map, 0, sizeof(temp_map));
Signature · 1 line
1.9.1
Signature · 1 line
Dmitry
#3 lore raw

Re: [PATCH v2 2/2] Input: amikbd - Allocate temporary keymap buffer on the stack

Hi Dmitry,

Quoted 11 lines · Dmitry Torokhov
Quoted 7 lines · Geert Uytterhoeven

Allocate the temporary buffer needed for initialization of the console keyboard maps (512 bytes, as NR_KEYS = 256) on the stack instead of statically, to reduce kernel size.

add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-512 (-512)
function old new delta
temp_map 512 - -512

So because it is marked __initdata and is placed into a separate section we have to allocate the space in the image?

Indeed. __initdata consumes space in both the vmlinux image and in memory.
Note that we don't have __initbss for uninitialized data, which would obviously still consume space in memory.

Quoted 1 line

Anyway, applied both, thank you.

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds