From: Mathias Krause <minipli@googlemail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Cc: Joe Perches <joe@perches.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org,
Mathias Krause <minipli@googlemail.com>
Subject: [PATCHv3 1/9] init.h: Add __init_str / __exit_str macros
Date: Thu, 21 Aug 2014 14:23:04 +0200 [thread overview]
Message-ID: <1408623792-7973-2-git-send-email-minipli@googlemail.com> (raw)
In-Reply-To: <1408623792-7973-1-git-send-email-minipli@googlemail.com>
Add macros to be able to mark string literals used in __init / __exit
functions.
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
v2: - use a better code example
---
include/linux/init.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/linux/init.h b/include/linux/init.h
index 2df8e8dd10..2c1cf10bb7 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -35,6 +35,20 @@
* Don't forget to initialize data not at file scope, i.e. within a function,
* as gcc otherwise puts the data into the bss section and not into the init
* section.
+ *
+ * For strings used in __init / __exit functions the __init_str() /
+ * __exit_str() macros will take care of marking the strings accordingly so
+ * they can be freed, too. Otherwise the strings would resist in memory, even
+ * though they are no longer referenced.
+ *
+ * Use them like this:
+ *
+ * static int __init my_setup(char *arg)
+ * {
+ * if (!strcmp(arg, __init_str("disable")))
+ * enabled = false;
+ * }
+ * __setup("mydev=", my_setup);
*/
/* These are for everybody (although not all archs will actually
@@ -45,6 +59,12 @@
#define __exitdata __section(.exit.data)
#define __exit_call __used __section(.exitcall.exit)
+/* Those can be used to mark strings used in __init / __exit functions. */
+#define __init_str(str) __mark_str(str, __UNIQUE_ID(_init_str_), __initconst)
+#define __exit_str(str) __mark_str(str, __UNIQUE_ID(_exit_str_), __exitdata)
+#define __mark_str(str, var, __section) \
+ ({ static const char var[] __section __aligned(1) = str; var; })
+
/*
* Some architecture have tool chains which do not handle rodata attributes
* correctly. For those disable special sections for const, so that other
--
1.7.10.4
next prev parent reply other threads:[~2014-08-21 12:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-21 12:23 [PATCHv3 0/9] Mark literal strings in __init / __exit code Mathias Krause
2014-08-21 12:23 ` Mathias Krause [this message]
2014-08-21 12:23 ` [PATCHv3 2/9] printk: Provide pi_<level> / pe_<level> macros for " Mathias Krause
2014-08-21 12:23 ` [PATCHv3 3/9] kallsyms: exclude pseudo symbols for __init / __exit strings Mathias Krause
2014-08-21 12:23 ` [PATCHv3 4/9] modpost: provide better diagnostics " Mathias Krause
2014-08-21 12:23 ` [PATCHv3 5/9] x86, acpi: Mark __init strings as such Mathias Krause
2014-08-21 12:23 ` [PATCHv3 6/9] x86, mm: Make x86_init.memory_setup() return a const char * Mathias Krause
2014-08-21 12:23 ` [PATCHv3 7/9] x86, mm: early_panic() - pass on the message as string Mathias Krause
2014-08-21 12:23 ` [PATCHv3 8/9] x86, mm: e820 - mark __init strings as such Mathias Krause
2014-08-21 12:23 ` [PATCHv3 9/9] x86: setup " Mathias Krause
2014-08-21 12:57 ` [PATCHv3 0/9] Mark literal strings in __init / __exit code Ingo Molnar
2014-08-21 14:29 ` Mathias Krause
2014-08-22 8:24 ` Ingo Molnar
2014-08-30 15:28 ` Mathias Krause
2014-09-16 8:57 ` Ingo Molnar
2014-08-21 16:25 ` Sam Ravnborg
2014-08-24 16:04 ` Mathias Krause
2014-08-24 16:28 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408623792-7973-2-git-send-email-minipli@googlemail.com \
--to=minipli@googlemail.com \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).