Skip to contentSkip to conversation

__init_msg(x) and friends macro

RFC PATCH In review [email protected] 2 participants 2 messages May 28, 2001

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 __init_msg(x) and friends macro

Hi all,

soryy for such ugly subject line, but I already sent this patch to LKML and didn't get any reply.

Patch adds __init_msg (and friends) macro that places its argument (string constant) into corresponding .data.init section and returns pointer to it. The goal of this patch is to allow constructions like this:

        static void __init foo(void)
	{
		printk(__init_msg(KERN_INFO "Some random long message "
				  "going to .data.init and then to bit bucket\n"));
	}

I hope this patch can save some memory and will be usefull :))

Best regards.

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 */
#1 lore raw

Hi!

Quoted 11 lines

Patch adds __init_msg (and friends) macro that places its argument (string constant) into corresponding .data.init section and returns pointer to it. The goal of this patch is to allow constructions like this:

        static void __init foo(void)
	{
		printk(__init_msg(KERN_INFO "Some random long message "
				  "going to .data.init and then to bit bucket\n"));
	}

I hope this patch can save some memory and will be usefull :))

I think it's better to teach GCC understanding another function attribute defining the default section of all read-only data defined in the function.

Have a nice fortnight

Signature · 2 lines
Martin `MJ' Mares <[email protected]> <[email protected]> http://atrey.karlin.mff.cuni.cz/~mj/
Even nostalgia isn't what it used to be.