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

Message ID 1425745546-28688-2-git-send-email-iulia.manda21@gmail.com
State New, archived
Headers show

Commit Message

Iulia Manda March 7, 2015, 4:25 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
macro.

Signed-off-by: Iulia Manda <iulia.manda21@gmail.com>
---
Changes since v2:
        - introduce a new header in order to avoid the inclusion of heavy weight
headers such as moduleparam.h; also, the inclusion of an existing header in all
the places where the static const variable is used may cause circular includes; 
          * this header contains the declaration for core_param variables and
shall be completed with other types of kernel command line parameters variable
declarations.
          * this may be just a temorary solution; if any other include file
seems to be more fitted for this, that suggestion is welcomed.

 include/linux/moduleparam.h |  9 +++++++++
 include/linux/params.h      | 12 ++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 include/linux/params.h

Patch
diff mbox

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)
+
+#ifdef CONFIG_CMDLINE_PARSE
+#define DEFINE_CORE_PARAM(name, var, val, type, perm)			\
+        type var = val;                                                 \
+        core_param(name, var, type, perm)
+#else
+#define DEFINE_CORE_PARAM(name, var, val, type, perm)
+#endif
+
 #endif /* !MODULE */
 
 /**
diff --git a/include/linux/params.h b/include/linux/params.h
new file mode 100644
index 0000000..c1ee6ff
--- /dev/null
+++ b/include/linux/params.h
@@ -0,0 +1,12 @@ 
+#ifndef _LINUX_PARAMS_H
+#define _LINUX_PARAMS_H
+
+#ifdef CONFIG_CMDLINE_PARSE
+#define DECLARE_CORE_PARAM(var, val, type)                              \
+        extern type var
+#else
+#define DECLARE_CORE_PARAM(var, val, type)                              \
+        static const type var = val
+#endif
+
+#endif /* _LINUX_INIT_H */