All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Input: amikbd - Fix build if !CONFIG_HW_CONSOLE
@ 2014-11-27  9:42 Geert Uytterhoeven
  2014-11-27  9:42 ` [PATCH 2/2] Input: amikbd - Allocate temporary keymap buffer dynamically Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-11-27  9:42 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-m68k, Geert Uytterhoeven

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.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Discovered during randconfig builds.
---
 drivers/input/keyboard/amikbd.c | 46 ++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 096d6067ae1f890f..4f81e65d9e35cb7d 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -45,6 +45,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 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);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Input: amikbd - Allocate temporary keymap buffer dynamically
  2014-11-27  9:42 [PATCH 1/2] Input: amikbd - Fix build if !CONFIG_HW_CONSOLE Geert Uytterhoeven
@ 2014-11-27  9:42 ` Geert Uytterhoeven
  2014-11-27 11:17   ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-11-27  9:42 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-m68k, Geert Uytterhoeven

Allocate the temporary buffer needed for initialization of the console
keyboard maps dynamically instead of statically, to reduce kernel size.

add/remove: 0/1 grow/shrink: 1/1 up/down: 12/-518 (-506)
function                                     old     new   delta
amikbd_probe                                 358     370     +12
vermagic                                      63      57      -6
temp_map                                     512       -    -512

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/input/keyboard/amikbd.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 4f81e65d9e35cb7d..fc98c5d10768cd2c 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -36,6 +36,7 @@
 #include <linux/interrupt.h>
 #include <linux/keyboard.h>
 #include <linux/platform_device.h>
+#include <linux/slab.h>
 
 #include <asm/amigaints.h>
 #include <asm/amigahw.h>
@@ -147,13 +148,18 @@ static unsigned char amikbd_keycode[0x78] __initdata = {
 
 static void __init amikbd_init_console_keymaps(void)
 {
+	unsigned short *temp_map;
+	size_t temp_map_size = NR_KEYS * sizeof(*temp_map);
 	int i, j;
 
+	temp_map = kmalloc(temp_map_size, GFP_KERNEL);
+	if (!temp_map)
+		return;
+
 	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));
+		memset(temp_map, 0, temp_map_size);
 		for (j = 0; j < 0x78; j++) {
 			if (!amikbd_keycode[j])
 				continue;
@@ -163,8 +169,10 @@ static void __init amikbd_init_console_keymaps(void)
 			if (!temp_map[j])
 				temp_map[j] = 0xf200;
 		}
-		memcpy(key_maps[i], temp_map, sizeof(temp_map));
+		memcpy(key_maps[i], temp_map, temp_map_size);
 	}
+
+	kfree(temp_map);
 }
 #else /* !CONFIG_HW_CONSOLE */
 static inline void amikbd_init_console_keymaps(void) {}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] Input: amikbd - Allocate temporary keymap buffer dynamically
  2014-11-27  9:42 ` [PATCH 2/2] Input: amikbd - Allocate temporary keymap buffer dynamically Geert Uytterhoeven
@ 2014-11-27 11:17   ` Andreas Schwab
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2014-11-27 11:17 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Dmitry Torokhov, linux-input, linux-m68k

Geert Uytterhoeven <geert@linux-m68k.org> writes:

> @@ -147,13 +148,18 @@ static unsigned char amikbd_keycode[0x78] __initdata = {
>  
>  static void __init amikbd_init_console_keymaps(void)
>  {
> +	unsigned short *temp_map;
> +	size_t temp_map_size = NR_KEYS * sizeof(*temp_map);
>  	int i, j;
>  
> +	temp_map = kmalloc(temp_map_size, GFP_KERNEL);
> +	if (!temp_map)
> +		return;
> +
>  	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));
> +		memset(temp_map, 0, temp_map_size);
>  		for (j = 0; j < 0x78; j++) {
>  			if (!amikbd_keycode[j])
>  				continue;

How about allocating it on the stack?  With NR_KEYS == 256 that means
512 bytes, which should be ok, doesn't it?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-27 11:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-27  9:42 [PATCH 1/2] Input: amikbd - Fix build if !CONFIG_HW_CONSOLE Geert Uytterhoeven
2014-11-27  9:42 ` [PATCH 2/2] Input: amikbd - Allocate temporary keymap buffer dynamically Geert Uytterhoeven
2014-11-27 11:17   ` Andreas Schwab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.