PATCH: moving strings to .init.data

Alexander V. Lukyanov (lav@long.yar.ru)
Thu, 26 Mar 1998 14:42:50 +0300


--vkogqOf2sHV7VnPd
Content-Type: text/plain; charset=us-ascii

Hi,

I have made a patch for init.h which allows relatively easy method to move
strings to .init.data section. I also converted ide.c to use the macros.

The method for string arrays is not very nice, but it works. In case of
ide.c it is even useful to assign numbers to strings and thus lower the
probability of error.

Note also that ide.c used before initialized non-static arrays. It was bad,
because it bloats code with array initialization.

The change of ide.c moved 497 bytes to .init.data section. Not too much,
but there are many drivers which can use the opportunity.

Alexander.

--vkogqOf2sHV7VnPd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=kernel_init_diff

--- include/linux/init.h.old Thu Mar 26 13:37:01 1998
+++ include/linux/init.h Thu Mar 26 14:01:06 1998
@@ -42,10 +42,13 @@
#define __init
#define __initdata
#define __initfunc(__arginit) __arginit
+#define __initstr(__str) __str
/* For assembly routines */
#define __INIT
#define __FINIT
#define __INITDATA
#endif
+
+#define __initastr(__name,__val) static const char __name[] __initdata = __val

#endif
--- include/asm-i386/init.h.old Thu Mar 26 13:32:40 1998
+++ include/asm-i386/init.h Thu Mar 26 14:00:39 1998
@@ -3,6 +3,7 @@

#define __init __attribute__ ((__section__ (".text.init")))
#define __initdata __attribute__ ((__section__ (".data.init")))
+#define __initstr(__str) ({ __initastr(__string_mem,__str); __string_mem; })
#define __initfunc(__arginit) \
__arginit __init; \
__arginit
--- drivers/block/ide.c.old Thu Mar 26 13:37:29 1998
+++ drivers/block/ide.c Thu Mar 26 14:20:12 1998
@@ -2111,8 +2111,8 @@
*/
__initfunc(static int match_parm (char *s, const char *keywords[], int vals[], int max_vals))
{
- static const char *decimal = "0123456789";
- static const char *hex = "0123456789abcdef";
+ __initastr(decimal,"0123456789");
+ __initastr(hex,"0123456789abcdef");
int i, n;

if (*s++ == '=') {
@@ -2220,16 +2220,25 @@
const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
const char max_hwif = '0' + (MAX_HWIFS - 1);

- printk("ide_setup: %s", s);
+ printk(__initstr("ide_setup: %s"), s);
init_ide_data ();

/*
* Look for drive options: "hdx="
*/
if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
- const char *hd_words[] = {"none", "noprobe", "nowerr", "cdrom",
- "serialize", "autotune", "noautotune",
- "slow", "swapdata", NULL};
+ __initastr(hd_word1,"none");
+ __initastr(hd_word2,"noprobe");
+ __initastr(hd_word3,"nowerr");
+ __initastr(hd_word4,"cdrom");
+ __initastr(hd_word5,"serialize");
+ __initastr(hd_word6,"autotune");
+ __initastr(hd_word7,"noautotune");
+ __initastr(hd_word8,"slow");
+ __initastr(hd_word9,"swapdata");
+ static const char *hd_words[] __initdata = {
+ hd_word1,hd_word2,hd_word3,hd_word4,hd_word5,
+ hd_word6,hd_word7,hd_word8,hd_word9,NULL };
unit = s[2] - 'a';
hw = unit / MAX_DRIVES;
unit = unit % MAX_DRIVES;
@@ -2251,7 +2260,7 @@
hwif->noprobe = 0;
goto done;
case -5: /* "serialize" */
- printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
+ printk(__initstr(" -- USE \"ide%d=serialize\" INSTEAD"), hw);
goto do_serialize;
case -6: /* "autotune" */
drive->autotune = 1;
@@ -2290,7 +2299,7 @@
if (vals[0] >= 20 && vals[0] <= 66)
idebus_parameter = vals[0];
else
- printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
+ printk(__initstr(" -- BAD BUS SPEED! Expected value from 20 to 66"));
goto done;
}
/*
@@ -2300,8 +2309,24 @@
/*
* Be VERY CAREFUL changing this: note hardcoded indexes below
*/
- const char *ide_words[] = {"noprobe", "serialize", "autotune", "noautotune", "reset", "nodma", "four",
- "qd6580", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL};
+ __initastr(ide_word1,"noprobe");
+ __initastr(ide_word2,"serialize");
+ __initastr(ide_word3,"autotune");
+ __initastr(ide_word4,"noautotune");
+ __initastr(ide_word5,"reset");
+ __initastr(ide_word6,"nodma");
+ __initastr(ide_word7,"four");
+ __initastr(ide_word8,"qd6580");
+ __initastr(ide_word9,"ht6560b");
+ __initastr(ide_wordA,"cmd640_vlb");
+ __initastr(ide_wordB,"dtc2278");
+ __initastr(ide_wordC,"umc8672");
+ __initastr(ide_wordD,"ali14xx");
+ __initastr(ide_wordE,"dc4030");
+ static const char *ide_words[] __initdata = {
+ ide_word1,ide_word2,ide_word3,ide_word4,ide_word5,
+ ide_word6,ide_word7,ide_word8,ide_word9,ide_wordA,
+ ide_wordB,ide_wordC,ide_wordD,ide_wordE, NULL};
hw = s[3] - '0';
hwif = &ide_hwifs[hw];
i = match_parm(&s[4], ide_words, vals, 3);
@@ -2316,7 +2341,7 @@
goto bad_hwif; /* chipset drivers are for "ide0=" only */
if (ide_hwifs[hw^1].chipset != ide_unknown)
goto bad_option; /* chipset for 2nd port already specified */
- printk("\n");
+ printk(__initstr("\n"));
}

switch (i) {
@@ -2427,17 +2452,17 @@

case 0: goto bad_option;
default:
- printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
+ printk(__initstr(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n"));
return;
}
}
bad_option:
- printk(" -- BAD OPTION\n");
+ printk(__initstr(" -- BAD OPTION\n"));
return;
bad_hwif:
- printk("-- NOT SUPPORTED ON ide%d", hw);
+ printk(__initstr("-- NOT SUPPORTED ON ide%d"), hw);
done:
- printk("\n");
+ printk(__initstr("\n"));
}

/*
@@ -2864,7 +2889,8 @@
while ((line = next) != NULL) {
if ((next = strchr(line,' ')) != NULL)
*next++ = 0;
- if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '='))
+ if (!strncmp(line,__initstr("ide"),3)
+ || (!strncmp(line,__initstr("hd"),2) && line[2] != '='))
ide_setup(line);
}
}

--vkogqOf2sHV7VnPd--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu