[OPW,kernel,v2,2/3] linux: Add macros that define and declare a core_param variable
diff mbox

Message ID 889439e78f119e729e7b6040bf4322417041bbb8.1425502513.git.iulia.manda21@gmail.com
State New, archived
Headers show

Commit Message

Iulia Manda March 4, 2015, 10:47 p.m. UTC
This patch introduces two macros for kernel command line arguments subsequently
defined as core parameters:
* DECLARE_CORE_PARAM - declares an extern variable in case CMDLINE_PARSE is
set. In the other case it will make the variable a static constant asigned with
a default value to enable constant folding;
* DEFINE_CORE_PARAM - defines a core_param variable if CMDLINE_PARSE is set. In
the other case it leaves the definition to be handled by DECLARE_CORE_PARAM

Signed-off-by: Iulia Manda <iulia.manda21@gmail.com>
Changes since v1:
        - make the variable static const instead of extern const; this allows
for constant folding in all the places where it is used;
        - by making the previous change the header containing the
implementation of the DECLARE_CORE_PARAM macro has to be included everywhere
var is used; for now, I chose to leave the definition and the declaration in
separate files. Having them both in moduleparam.h causes:
          * circular includes (in the headers that are included in
moduleparam.h and that would use DECLARE_CORE_PARAM);
          * a lot of lines of code added and also some bloated code because of
the inclusion of moduleparam.h in multiple files.
          * naive solution: add a new header file containing the macros;
        - get rid of hardcoded types and dummy variable;
        - keep consistency;

 include/linux/init.h        | 8 ++++++++
 include/linux/moduleparam.h | 9 +++++++++
 2 files changed, 17 insertions(+)

diff mbox

diff --git a/include/linux/init.h b/include/linux/init.h
index 2df8e8d..ce6d39b 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -155,6 +155,14 @@  int __init init_rootfs(void);
 extern void (*late_time_init)(void);
+#define DECLARE_CORE_PARAM(var, val, type)                              \
+        extern type var
+#define DECLARE_CORE_PARAM(var, val, type)                              \
+        static const type var = val
 extern bool initcall_debug;
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index f97397c..17efa97 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -310,6 +310,15 @@  static inline void __kernel_param_unlock(void)
 #define core_param(name, var, type, perm)				\
 	param_check_##type(name, &(var));				\
 	__module_param_call("", name, &param_ops_##type, &var, perm, -1, 0)
+#define DEFINE_CORE_PARAM(name, var, val, type, perm)			\
+        type var = val;                                                 \
+        core_param(name, var, type, perm)
+#define DEFINE_CORE_PARAM(name, var, val, type, perm)
 #endif /* !MODULE */