Skip to content

Commit 40a826b

Browse files
petrpavludkruces
authored andcommitted
module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN
The maximum module name length (MODULE_NAME_LEN) is somewhat confusingly defined in terms of the maximum parameter prefix length (MAX_PARAM_PREFIX_LEN), when in fact the dependency is in the opposite direction. This split originates from commit 730b69d ("module: check kernel param length at compile time, not runtime"). The code needed to use MODULE_NAME_LEN in moduleparam.h, but because module.h requires moduleparam.h, this created a circular dependency. It was resolved by introducing MAX_PARAM_PREFIX_LEN in moduleparam.h and defining MODULE_NAME_LEN in module.h in terms of MAX_PARAM_PREFIX_LEN. Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN for clarity. This matches the similar approach of defining MODULE_INFO in module.h and __MODULE_INFO in moduleparam.h. Signed-off-by: Petr Pavlu <[email protected]> Reviewed-by: Daniel Gomez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Gomez <[email protected]>
1 parent a7c54b2 commit 40a826b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/linux/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/percpu.h>
3434
#include <asm/module.h>
3535

36-
#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
36+
#define MODULE_NAME_LEN __MODULE_NAME_LEN
3737

3838
struct modversion_info {
3939
unsigned long crc;

include/linux/moduleparam.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
#include <linux/stringify.h>
77
#include <linux/kernel.h>
88

9+
/*
10+
* The maximum module name length, including the NUL byte.
11+
* Chosen so that structs with an unsigned long line up, specifically
12+
* modversion_info.
13+
*/
14+
#define __MODULE_NAME_LEN (64 - sizeof(unsigned long))
15+
916
/* You can override this manually, but generally this should match the
1017
module name. */
1118
#ifdef MODULE
@@ -17,9 +24,6 @@
1724
#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
1825
#endif
1926

20-
/* Chosen so that structs with an unsigned long line up. */
21-
#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
22-
2327
#define __MODULE_INFO(tag, name, info) \
2428
static const char __UNIQUE_ID(name)[] \
2529
__used __section(".modinfo") __aligned(1) \
@@ -284,7 +288,7 @@ struct kparam_array
284288

285289
/* This is the fundamental function for registering boot/module parameters. */
286290
#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
287-
static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \
291+
static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \
288292
static const char __param_str_##name[] = prefix #name; \
289293
static struct kernel_param __moduleparam_const __param_##name \
290294
__used __section("__param") \

0 commit comments

Comments
 (0)