Skip to contentSkip to conversation

small addition to <linux/init.h>

PATCH New [email protected] 1 participant 1 message May 14, 2001

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 small addition to <linux/init.h>

Hi all,

please take a quick look at attached patch (IMHO it can be usefull :)

The code below is a common code pattern in Linux kernel:

static int __init foo(void)

{
	. . .
	printk("%s: blah blah blah\n", bar);
	. . .
}

this is bad because "blah blah blah\n" goes to .rodata section and plagues the memory. With this small patch it's possibe to rewrite this fragment as:

static int __init foo(void)

{
	. . .
	printk(__init_msg("%s: blah blah blah\n"), bar);
	. . .
}

and thus "blah blah blah\n" goes to .data.init and then to bitbucket. IMHO it can save some extra memory for us.

Best regadrs.

Signature · 2 lines
Andrey Panin            | Embedded systems software engineer
[email protected]        | PGP key: http://www.orbita1.ru/~pazke/AndreyPanin.asc
include/linux/init.h +5 -0
diff -ur linux.vanilla/include/linux/init.h linux/include/linux/init.h
@@ -155,4 +155,9 @@
 #define __devexitdata __exitdata
 #endif
 
+#define __init_msg(x) ({ static char msg[] __initdata = (x); msg; })
+#define __exit_msg(x) ({ static char msg[] __exitdata = (x); msg; })
+#define __devinit_msg(x) ({ static char msg[] __devinitdata = (x); msg; })
+#define __devexit_msg(x) ({ static char msg[] __devexitdata = (x); msg; })
+
 #endif /* _LINUX_INIT_H */