[PATCH 21/25] dynamic_debug: protect "dyndbg" fake module param name at compile-time
From: jim . cromie
Date: Mon Dec 12 2011 - 18:14:59 EST
From: Jim Cromie <jim.cromie@xxxxxxxxx>
Add BUILD_BUG_DECL(name, cond) to cause compile error if condition is
true. Unlike other flavors of BUILD_BUG_*, this works at file scope;
it declares an unused 0-sized var: __BUILD_BUG_DECL_##name, whose
declaration is readily found if compile errors happen.
Use this macro in module_param_named() to insure that "dyndbg" is
reserved and not used by modules as a param name, and drop the
run-time check for same.
Signed-off-by: Jim Cromie <jim.cromie@xxxxxxxxx>
---
include/linux/kernel.h | 10 ++++++++++
include/linux/moduleparam.h | 1 +
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e8b1597..f137bed 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -665,6 +665,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
#define BUILD_BUG_ON_ZERO(e) (0)
#define BUILD_BUG_ON_NULL(e) ((void*)0)
#define BUILD_BUG_ON(condition)
+#define BUILD_BUG_DECL(name, condition)
#else /* __CHECKER__ */
/* Force a compilation error if a constant expression is not a power of 2 */
@@ -703,6 +704,15 @@ extern int __build_bug_on_failed;
if (condition) __build_bug_on_failed = 1; \
} while(0)
#endif
+/*
+ * BUILD_BUG_DECL is usable at file scope (by avoiding do {} loop).
+ * If condition is true, causes a compile error, otherwize it declares
+ * a 0-sized array (so it doesn't waste space)
+ */
+#define BUILD_BUG_DECL(name, condition) \
+ static struct __BUILD_BUG_DECL_ ##name { \
+ int __BUILD_BUG_DECL_ ##name[1 - 2*!!(condition)]; \
+ } __BUILD_BUG_DECL_ ##name[0] __attribute__((unused))
#endif /* __CHECKER__ */
/* Trap pasters of __FUNCTION__ at compile-time */
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 3e272c7..9e7d196 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -118,6 +118,7 @@ struct kparam_array
* structure. This allows exposure under a different name.
*/
#define module_param_named(name, value, type, perm) \
+ BUILD_BUG_DECL(name, !__builtin_strcmp(#name, "dyndbg")); \
param_check_##type(name, &(value)); \
module_param_cb(name, ¶m_ops_##type, &value, perm); \
__MODULE_PARM_TYPE(name, #type)
--
1.7.7.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/